Swagger Editor 3.0 How to code component schemas for java maps - validation

I have an response schema that contains java URI, Set and Map.
I can't find any example how to code this yaml part for swagger.
How to write the URI, Set and Map part in yaml components: schemas: see below.
My response java code looks like below.
public class ShowStaticInfo {
private String Id;
private long time;
private URI poster;
private Set<Tag> tags;
private HashMap<String,Tag> objectCreated;
And the written yaml code like this.
As stated above this yaml needs to be changed.
openapi: "3.0.1"
info:
title: Mobile backend
version: 1.0.0
license:
name: Apache 2.0
servers:
- url: https://development.cybercom.com/services/6
description: Development server
- url: https://staging.cybercom.com/services
description: Staging server
- url: https://production.cybercom.com/services
description: Production server
paths:
/buildinfo:
get:
description: Returns the build information (Version and Time stamp).
operationId: getBuildInfo
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/BuildInfo'
parameters:
- in: header
name: LBPATH
schema:
type: string
/countries/{countryId}/cities/{cityId}/showinfo/static:
get:
description: Returns a list of static show information for a city.
operationId: getShowStaticInfo
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ShowStaticInfo'
parameters:
- in: path
name: countryId
required: true
schema:
type: string
- in: path
name: cityId
required: true
schema:
type: string
- in: header
name: Accept-Language
schema:
type: string
- in: header
name: LBPATH
schema:
type: string
components:
schemas:
BuildInfo:
properties:
version:
type: string
timestamp:
type: string
status:
type: string
ShowStaticInfo:
properties:
poster:
$ref: '#/components/schemas/URI'
time:
type: integer
format: int64
showId:
type: string
tags:
$ref: '#/components/schemas/Set'
showObjectCreated:
$ref: '#/components/schemas/HashMap'

Related

How To ignore Endpoints from openapi.yaml in generation with openapi-generator-maven-plugin/

yaml and openapi-generator-maven-plugin is corretly generating Spring Boot Controller Interfaces from it. All is working fine. But now we want to overwrite one of the generated Interfaces with our own interface. How can we exclude a certain endpoint from this generation?
Example:
paths:
/currencies:
get:
tags:
- DomainData
summary: Lists all valid currencies available.
operationId: "getCurrencies"
parameters:
- $ref: '#/components/parameters/AcceptLanguage'
responses:
"200":
description: "OK"
content:
application/json:
schema:
type: string
additionalProperties:
type: string
'401':
$ref: '#/components/responses/Unauthorized'
'5XX':
$ref: '#/components/responses/Unexpected'
/languages:
get:
tags:
- DomainData
summary: Lists all valid languages available.
operationId: "getLanguages"
parameters:
- $ref: '#/components/parameters/AcceptLanguage'
responses:
"200":
description: "OK"
content:
application/json:
schema:
type: string
additionalProperties:
type: string
'401':
$ref: '#/components/responses/Unauthorized'
'5XX':
$ref: '#/components/responses/Unexpected'
This is a part of the openapi.yaml and we would not like to generate for /languages but everything else.
I found a solution we used a .openapi-generator-ignore
and linked it in the pom options of the openapi generator.
In the .openapi-generator-ignore we used the full relative path from position of the ignore file to the file that is not existing and we dont want to get generated.
target/generated-sources/v1/src/main/java/ch/company/dsp/bff/project/generated/api/languageApi.java

How to build multimodule gradle project with each module having its own Open API spec and the parent has all spec merge together on build

I am designing one application, the application should merge OpenAPI-3 specification files into a single file.
Consider the following open api v3 schema files color.yaml and book.yaml
color.yaml
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: http://localhost:8080
description: Generated server url
paths:
/api/color/{name}:
get:
tags:
- color-controller
operationId: getColor
parameters:
- name: name
in: path
required: true
schema:
type: string
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/Color'
components:
schemas:
Color:
type: object
properties:
name:
type: string
red:
type: integer
format: int32
green:
type: integer
format: int32
blue:
type: integer
format: int32
book.yaml
openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: http://localhost:8080
description: Generated server url
paths:
/api/book/{name}:
get:
tags:
- book-controller
operationId: getBook
parameters:
- name: name
in: path
required: true
schema:
type: string
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/Book'
components:
schemas:
Book:
type: object
properties:
name:
type: string
iban:
type: string
</code>
The parent module should merge these files into a single master yaml spec file
**merged.yaml**
openapi: 3.0.1
info:
title: My title
version: 1.0.0-SNAPSHOT
servers:
- url: http://localhost:8080
description: Generated server url
paths:
/api/book/{name}:
get:
tags:
- book-controller
operationId: getBook
parameters:
- name: name
in: path
required: true
style: simple
explode: false
schema:
type: string
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/Book'
/api/color/{name}:
get:
tags:
- color-controller
operationId: getColor
parameters:
- name: name
in: path
required: true
style: simple
explode: false
schema:
type: string
responses:
"200":
description: OK
content:
'*/*':
schema:
$ref: '#/components/schemas/Color'
components:
schemas:
Book:
type: object
properties:
name:
type: string
iban:
type: string
Color:
type: object
properties:
name:
type: string
red:
type: integer
format: int32
green:
type: integer
format: int32
blue:
type: integer
format: int32
Also when I do changes to specific sub-module spec file it should reflect in parent spec file and should show in swagger-ui for testing.
Regarding the merging part of your question:
You can use APIMatic's API spec merge feature to first merge your specs and then transform the merged output into OpenAPI's format. Here are the steps:
Structure your directory as follows:
dir\
spec1\
color.yaml
spec2\
book.yaml
APIMATIC-META.json
A minimalistic APIMATIC-META.json can look like this to enable merging:
{
"MergeConfiguration": {
"MergedApiName": "My title",
"MergeApis": true,
"MergeSettings": {
"SkipCodeGenValidation": true
}
}
}
ZIP the directory, upload it and transform it via their website to OpenAPI v3 to get your merged output. Here is a link that provides step by step guide on uploading and performing a transformation: https://docs.apimatic.io/manage-apis/api-merging/#transforming-the-zipped-file
If you are looking to automate the process, APIMatic has an API too: https://www.apimatic.io/docs/api#/http/api-endpoints/transformation/transform-via-file

Failing to add examples to YAML file

Purpose: Add examples to yaml file so it will be exposed in Postman collection.
I'm trying to add 2 simple example but keep getting errors. The current error is : missed comma between flow collection entries.
Can you please assist?
swagger: "2.0"
info:
description: "Test"
version: "1.4.4"
title: "my-test"
host: "somehost"
basePath: "/somepath"
schemes:
- "https"
tags:
- name: Recommend
description: helloWorld
paths:
/hello:
post:
description: "some description"
operationId: "example-test"
tags: ["example-test"]
produces:
"application/json"
parameters:
name: "myRequest"
in: "body"
description: "bla"
required: true
schema:
$ref: "#/definitions/myRequest"
examples: {ex1: $ref: "#/components/examples/test1" , ex2: $ref: "#/components/examples/test2" }
responses:
"204":
description: "All good"
definitions:
myRequest:
type: object
required:
- name
- lastname
properties:
name:
type: string
lastname:
type: string
components:
examples:
test1:
value:
name: test1
lastname: test1
test2:
value:
name: test2
lastname: test2
You are mixing up OpenAPI 2.0 and 3.0 syntax.
Multiple examples are supported in OpenAPI 3.0 only. The correct syntax is:
openapi: 3.0.0
...
paths:
/hello:
post:
description: "some description"
operationId: "example-test"
tags: ["example-test"]
requestBody: # <------
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/myRequest"
examples: # <------
ex1:
$ref: "#/components/examples/test1"
ex2:
$ref: "#/components/examples/test2"
responses:
"204":
description: "All good"
components:
schemas:
myRequest:
...
examples:
test1:
value:
name: test1
lastname: test1
test2:
value:
name: test2
lastname: test2
If you use OpenAPI 2.0 (swagger: '2.0), you can only define a single example, and this example must be specified inline, it cannot be $referenced.
swagger: "2.0"
...
paths:
/hello:
post:
description: "some description"
operationId: "example-test"
tags: ["example-test"]
produces:
- "application/json" # <---- Note the leading dash here
parameters:
- name: "myRequest" # <---- Note the leading dash here
in: "body"
description: "bla"
required: true
schema:
$ref: "#/definitions/myRequest"
responses:
"204":
description: "All good"
definitions:
myRequest:
type: object
required:
- name
- lastname
properties:
name:
type: string
lastname:
type: string
example: # <---- Example value for a schema
name: test1
lastname: test1

Accept only defined parameters for generated Spring-Server

First, I generated a spring-server using https://editor.swagger.io/.
The spring-server works quite well, but ignores these parameters that were not defined by me. So if I send a request to the server with the following JSON,
{
"art": "PK",
"termin": "2019-12-31",
"betrag": 120000,
"test": "test"
}
then I want to get an error, because the parameter "test" is not defined in my swagger.
My swagger code looks like this:
openapi: 3.0.1
info:
...
...
paths:
/vorgang:
post:
tags:
- vorgang
summary: Adds a vorgang
description: Adds a vorgang
operationId: addVorgang
requestBody:
description: procedure object
content:
application/json:
schema:
$ref: '#/components/schemas/Vorgang'
required: true
...
...
components:
schemas:
Vorgang:
type: object
properties:
art:
type: string
enum:
- PK
- FK
termin:
type: string
format: date
betrag:
type: number
format: double
required:
- art
- termin
- betrag

openapi generator maven plugin : Polymorphism support

I have written YAML files with polymorphism syntax but i get a nullpointer error whenever maven plugin parses a definition with polymorphism schema.
Does "openapi-generator-maven-plugin" supports polymorphic YAML files to generate java stubs?
An example of polymorphis definition :
IRFloatSwapLegDO:
title: IRFloatSwapLegDO
allOf:
- $ref: '#/definitions/IRSwapLegDO'
- type: object
properties:
amortizationSchedule:
$ref: '#/definitions/AmortizationScheduleDO'
compoundingSchedule:
$ref: '#/definitions/CompoundingScheduleDO'
couponSchedule:
$ref: '#/definitions/CouponScheduleDO'
currency:
$ref: '#/definitions/CurrencyDO'
dayCountConvention:
type: string
fixInArrears:
type: boolean
fixingMultiplier:
type: number
format: double
fixingSchedule:
$ref: '#/definitions/CompoundingScheduleDO'
irSwapLegType:
type: string
enum:
- IRFixedSwapLeg
- IRFloatSwapLeg
irUnderlying:
$ref: '#/definitions/IRUnderlyingDO'
legID:
type: string
notional:
type: number
format: double
notionalExchange:
$ref: '#/definitions/NotionalExchangeDO'
overriddenFixings:
$ref: '#/definitions/CouponScheduleDO'
payAtStart:
type: boolean
schedule:
$ref: '#/definitions/ScheduleDO'
title: IRFloatSwapLegDO
Below is the exception which i get:
java.lang.NullPointerException
at io.swagger.v3.parser.util.OpenAPIDeserializer.getObject(OpenAPIDeserializer.java:730)
at io.swagger.v3.parser.util.OpenAPIDeserializer.getSchema(OpenAPIDeserializer.java:1957)
at io.swagger.v3.parser.ResolverCache.loadRef(ResolverCache.java:147)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:48)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefSchema(ExternalRefProcessor.java:644)
at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalSchema(ExternalRefProcessor.java:115)

Resources