Skip to content
Snippets Groups Projects
Commit 84d34ecc authored by Jueun Park's avatar Jueun Park
Browse files

add yaml for oas ver 3.1, processed relast

parent 4ee2200d
No related branches found
No related tags found
1 merge request!1Tests/openapi generator
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
Showing
with 1166 additions and 41 deletions
......@@ -24,8 +24,7 @@ dependencies {
implementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-yaml', version: '2.9.8'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation group: 'com.flipkart.zjsonpatch', name: 'zjsonpatch', version: '0.4.11'
implementation group: 'org.openapi4j', name: 'openapi-parser', version: '1.0.7'
implementation group: 'org.openapitools', name: 'openapi-generator-gradle-plugin', version: '5.4.0'
implementation group: 'io.swagger.parser.v3', name: 'swagger-parser', version: '2.0.30'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.7.0'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.0'
......@@ -105,7 +104,7 @@ jastadd {
}
jastadd {
basedir "src/main/jastadd/"
basedir "src/gen/jastadd/"
include "**/*.ast"
include "**/*.jadd"
include "**/*.jrag"
......
package de.tudresden.inf.st.openapi;
import de.tudresden.inf.st.openapi.ast.OpenAPIObject;
import org.openapi4j.core.validation.ValidationResults;
import org.openapi4j.parser.OpenApi3Parser;
import org.openapi4j.parser.model.v3.OpenApi3;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static de.tudresden.inf.st.openapi.ast.ASTNode.assertNotNull;
public class OpenAPIMain {
......@@ -19,9 +14,6 @@ public class OpenAPIMain {
* main-method, calls the set of methods to test the OpenAPI-Generator with JastAdd
**/
public static void main(String[] args) throws Exception {
OpenAPIObject openApi = new OpenAPIObject();
OpenApi3 api3;
ValidationResults results;
List<String> filenames = new ArrayList<>();
String genDir = "./gen-api-ex/";
File genDirectory = new File(genDir);
......@@ -29,27 +21,10 @@ public class OpenAPIMain {
File resource = new File("./src/main/resources");
for (File file : resource.listFiles())
filenames.add(file.getName());
System.out.println(filenames.size());
/*
for( String file : filenames ){
String writerName = genDir + file;
URL expUrl = OpenAPIMain.class.getClassLoader().getResource(file);
OpenApi3 api = new OpenApi3Parser().parse(expUrl, new ArrayList<>(), true);
System.out.println("Loading expression DSL file '" + file + "'.");
String fileName = "./src/main/resources/3.1/basicref.yaml";
openApi = OpenAPIObject.parseOpenAPI(api);
api3 = OpenAPIObject.composeOpenAPI(openApi);
openApi.generateRequests();
}
*/
String fileName = "petstore-v2.yaml";
//FileWriter writer = new FileWriter("./gen-api-ex/callback-example_generated.json");
URL expUrl = OpenAPIMain.class.getClassLoader().getResource(fileName);
File file = null;
......@@ -62,18 +37,8 @@ public class OpenAPIMain {
throw new FileNotFoundException("Could not load JSON file " + fileName);
}
OpenApi3 api = new OpenApi3Parser().parse(expUrl, new ArrayList<>(), true);
System.out.println("Loading expression DSL file '" + fileName + "'.");
//openApi = OpenAPIObject.parseOpenAPI(api);
//openApi.generateRequestsWithInferredParameters();
//writer.write(api3.toNode().toPrettyString());
//writer.close();
Map<String, List<String>> s = new HashMap<>();
if (args.length > 0) {
fileName = args[0];
}
......
openapi: "3.1.0"
x-oas-internal: test reserved keyword
x-oai-extension: test reserved keyword
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
identifier: test
servers:
- url: http://petstore.swagger.io/v1
webhooks:
# Each webhook needs a name
newPet:
# This is a Path Item Object, the only difference is that the request is initiated by the API provider
post:
requestBody:
description: Information about a new pet in the system
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
description: pet
responses:
"200":
description: Return a 200 status to indicate that the data was received successfully
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
"200":
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
description: error
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
"201":
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Tag"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
- $ref: "#/components/parameters/User"
description: user
summary: user
responses:
"200":
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
parameters:
User:
in: query
description: user
name: user
schema:
type: string
schemas:
Pet:
type:
- object
- string
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
testenum:
type: string
enum:
- available
- pending
- sold
default: available
testconst:
type: string
const: pending
tag:
type: string
arbitraryKeyword: test
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
tag:
$ref: "#/components/schemas/Tag"
Tag:
type:
- object
- string
- string
- foo
properties:
id:
type: integer
format: int64
name:
type: string
openapi: "3.1.0"
jsonSchemaDialect: https://json-schema.org/draft/2020-12/schema
info:
version: 1.0.0
summary: test summary in info object
description: description in info object
title: Swagger Petstore
license:
name: MIT
identifier: test identifier
servers:
- url: http://petstore.swagger.io/v1
- url: http://{host}.swagger.io/v1
variables:
host:
default: demo
description: this value is assigned by the service provider
enum: []
webhooks:
# Each webhook needs a name
newPet:
# This is a Path Item Object, the only difference is that the request is initiated by the API provider
post:
requestBody:
description: Information about a new pet in the system
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
description: pet
responses:
"200":
description: Return a 200 status to indicate that the data was received successfully
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
"200":
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
description: error
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
"201":
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Tag"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
- $ref: "#/components/parameters/User"
description: user
summary: user
responses:
"200":
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
pathItems:
pets:
get:
description: Returns all pets from the system that the user has access to
responses:
'200':
description: A list of pets.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/pet'
parameters:
User:
in: query
description: user
name: user
schema:
type: string
schemas:
Pet:
type:
- object
- string
- array
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
writeOnly: true
readOnly: true
testenum:
type: string
enum:
- available
- pending
- sold
default: available
testconst:
type: string
const: pending
tag:
type: string
arbitraryKeyword: test
$ref: ./ex.json#user-profile
Pets:
type: 'null'
default: "I'm a string"
exclusiveMaximum: 12
exclusiveMinimum: 1
items:
$ref: "#/components/schemas/Pet"
ArrayWithoutItems:
type: array
ItemsWithoutArrayType:
type: object
items:
item1:
type: object
item2:
type: string
item3: what
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
tag:
$ref: "#/components/schemas/Tag"
Tag:
type:
- object
- string
- string
- foo
properties:
id:
type: integer
format: int64
name:
type: string
patternProperties:
'[a-b].*': 1
MapAnyValue:
additionalProperties: { }
openapi: 3.1.0
info:
version: "1.0.0"
title: parse-api
description: Test swagger-parser
paths:
/parse:
get:
description: Parser test
operationId: getParse
parameters:
- in: query
name: parse
required: true
schema:
$ref: 'http://localhost:${dynamicPort}/domain#/components/schemas/Parse'
- in: query
name: relativeParse
required: true
schema:
$ref: './domain.yaml#/components/schemas/Parse'
responses:
'200':
description: OK
content:
"application/json":
schema:
$ref: './domain.yaml#/components/schemas/Parse'
openapi: 3.1.0
info:
title: Parser Test
version: '1.0'
components:
schemas:
Parse:
$ref: '#/components/schemas/ParseEnum'
description: Overwritten description
ParseEnum:
title: Parse It
description: Can it parse it?
type:
- string
- object
enum:
- Yes
- No
NestedRef:
$ref: './domainref.yaml#/components/schemas/Parse'
openapi: 3.1.0
info:
title: Parser Test
version: '1.0'
components:
schemas:
NestedParse:
$ref: '#/components/schemas/NestedParseEnum'
description: Overwritten description
NestedParseEnum:
title: Parse It
description: Can it parse it?
type:
- string
- object
enum:
- Yes
- No
openapi: 3.1.0
info:
version: "1.0.0"
title: parse-api
description: Test swagger-parser
paths:
/parse:
get:
description: Parser test
operationId: getParse
parameters:
- in: query
name: parse
required: true
schema:
$ref: 'http://localhost:${dynamicPort}/domain#/components/schemas/Parse'
- in: query
name: relativeParse
required: true
schema:
$ref: './domain.yaml#/components/schemas/Parse'
responses:
'200':
description: OK
content:
"application/json":
schema:
$ref: './nested/domain.yaml#/components/schemas/NestedRef'
openapi: "3.1.0"
x-oas-internal: test reserved keyword
x-oai-extension: test reserved keyword
jsonSchemaDialect: 'https://json-schema.org/draft/2020-12/schema'
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
identifier: test
servers:
- url: http://petstore.swagger.io/v1
webhooks:
# Each webhook needs a name
newPet:
# This is a Path Item Object, the only difference is that the request is initiated by the API provider
post:
requestBody:
description: Information about a new pet in the system
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
description: pet
responses:
"200":
description: Return a 200 status to indicate that the data was received successfully
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
"200":
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
description: error
security:
- mutualTLS: [ ]
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
"201":
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Tag"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
- $ref: "#/components/parameters/User"
description: user
summary: user
responses:
"200":
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
parameters:
User:
in: query
description: user
name: user
schema:
type: string
schemas:
Pet:
type:
- object
- string
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
testenum:
type: string
enum:
- available
- pending
- sold
default: available
testconst:
type: string
const: pending
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
tag:
$ref: "#/components/schemas/Tag"
Tag:
type:
- object
- string
- string
- foo
properties:
id:
type: integer
format: int64
name:
type: string
openapi: "3.1.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
identifier: test
servers:
- url: http://petstore.swagger.io/v1
webhooks:
# Each webhook needs a name
newPet:
# This is a Path Item Object, the only difference is that the request is initiated by the API provider
post:
requestBody:
description: Information about a new pet in the system
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
responses:
"200":
description: Return a 200 status to indicate that the data was received successfully
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
"200":
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
"201":
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
"200":
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type:
- string
- integer
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
openapi: "3.1.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
identifier: test
servers:
- url: http://petstore.swagger.io/v1
webhooks:
# Each webhook needs a name
newPet:
# This is a Path Item Object, the only difference is that the request is initiated by the API provider
post:
requestBody:
description: Information about a new pet in the system
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
responses:
"200":
description: Return a 200 status to indicate that the data was received successfully
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
x-extension: test
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
"200":
description: An paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
"201":
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
"200":
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type:
- string
- integer
tag:
type: string
Pets:
$id: test
$anchor: test
type: array
items:
$ref: "#/components/schemas/Pet"
description: desc
format: int32
Error:
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
DiscriminatorExtension:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Lizard'
discriminator:
propertyName: petType
x-extension: test
pathItems:
pets:
get:
description: Returns all pets from the system that the user has access to
responses:
'200':
description: A list of pets.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/pet'
openapi: 3.1.0
info:
title: siblings JSONSchema
version: 1.0.0
servers:
- url: /
paths: { }
components:
schemas:
Payment:
type: object
properties:
name:
type: string
credit_card:
type: number
billing_address:
type: string
required:
- name
dependentRequired:
credit_card:
- billing_address
PaymentMethod:
type: object
properties:
name:
type: string
credit_card:
type: number
required:
- name
dependentSchemas:
credit_card:
properties:
billing_address:
type: string
required:
- billing_address
IfTest:
title: Person
type: object
properties:
country:
type: string
widget: Select
enum:
- usa
- canada
- eu
default: eu
required:
- country
if:
properties:
country:
type: string
const: canada
then:
properties:
maple_trees:
type: number
else:
properties:
accept:
type: boolean
const: true
required:
- accept
Fruit:
type: string
examples:
- apple
- orange
Error:
type: object
properties:
code:
type: integer
message:
type: string
examples:
- code: 123
message: Oops...
- code: 456
message: Feature is not available for your plan
openapi: 3.1.0
servers:
- url: /v2
info:
version: 1.0.0
title: Swagger Petstore
paths:
/pet:
post:
tags:
- pet
summary: Add a new pet to the store
description: ''
operationId: addPet
responses:
'405':
description: Invalid input
security:
- api_key: []
requestBody:
$ref: '#/components/requestBodies/Pet'
put:
tags:
- pet
summary: Update an existing pet
description: ''
operationId: updatePet
responses:
'400':
description: Invalid ID supplied
'404':
description: Pet not found
'405':
description: Validation exception
security:
- petstore_auth:
- 'write:pets'
- 'read:pets'
requestBody:
$ref: '#/components/requestBodies/Pet'
/petType:
post:
tags:
- petType
summary: Add a new pet to the store
description: ''
operationId: addPet
responses:
'405':
description: Invalid input
security:
- mutual_TLS: [ ]
requestBody:
$ref: '#/components/requestBodies/Pet'
components:
requestBodies:
Pet:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
application/xml:
schema:
$ref: '#/components/schemas/Pet'
description: Pet object that needs to be added to the store
required: true
securitySchemes:
petstore_auth:
type: oauth2
description: This is a description
flows:
implicit:
authorizationUrl: 'http://petstore.swagger.io/oauth/dialog'
scopes:
'write:pets': modify pets in your account
'read:pets': read your pets
api_key:
type: apiKey
name: api_key
description: This is another description
in: header
mutual_TLS:
type: mutualTLS
name: name mutualTLS
description: This is another description
in: header
schemas:
Pet:
type: object
required:
- name
- photoUrls
properties:
id:
type: integer
format: int64
name:
type: string
example: doggie
photoUrls:
type: array
xml:
name: photoUrl
wrapped: true
items:
type: string
status:
type: string
description: pet status in the store
enum:
- available
- pending
- sold
xml:
name: Pet
\ No newline at end of file
openapi: "3.1.0"
info:
version: 1.0.0
title: Swagger Petstore
paths:
/pets:
$ref: "#/components/pathItems/Pets"
summary: List all pets
description: description
/pets/{petId}:
get:
summary: Info for a specific pet
operationId: showPetById
security:
- apiKey: [ ]
tags:
- pets
parameters:
- $ref: "#/components/parameters/Pets"
description: The id of the pet to retrieve
responses:
"200":
$ref: "#/components/responses/Pets"
description: Expected response to a valid request
/pets/requestBody:
post:
description: It gets pets
responses:
'200':
description: successful operation
headers:
X-Rate-Limit:
$ref: "#/components/headers/Pets"
description: header sibling description
links:
userRepository:
$ref: '#/components/links/userRepository'
description: link sibling description
requestBody:
$ref: "#/components/requestBodies/Pets"
description: request body description
components:
securitySchemes:
api_key:
$ref: "#/components/securitySchemes/security"
description: This is another description
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment