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

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

Related

Multipart don't working for ArrayObject files with Open Api 4.3.1 Version

Description
Hi Everyone. I am working with open api generator and change for only use Reactor in my projects (Flux and Mono). My problem is when I generate Multipart form for object array files, the generator create #RequestPart with Mono and it's will be geerate with Flux because the object is an array.
I check the mustaches templates for form params and all it's ok.
This is part of my formParams.mustache
{{#reactive}}{{#isArray}}Flux{{/isArray}}{{^isArray}}Mono{{/isArray}}{{/reactive}}{{^reactive}}{{#isArray}}List<{{/isArray}}MultipartFile{{#isArray}}>{{/isArray}}{{/reactive}}
My question is: why the generator don't validate when "isArray" because always generate with Mono in my classes.
This is an example how to generate my ApiDelegate:
with single element (Ok): default Mono multipartSingle(Mono file, ServerWebExchange exchang
My Open api YAML is:
openapi: 3.0.1
info:
title: Test multipart
version: v1
servers:
- url: http://localhost:9111/api-test/multipart/v1
description: Generated server url
paths:
/multipart/single:
post:
tags:
- multipart
description: Single MultipartFile test
operationId: multipartSingle
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
file:
description: "One file"
type: string
format: binary
responses:
'200':
description: successful operation, name of the uploaded file
content:
application/json:
schema:
$ref: '#/components/schemas/InformationPart'
/multipart-array:
post:
tags:
- multipart
description: MultipartFile array test
operationId: multipartArray
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
files:
type: array
description: "Many files"
items:
type: string
format: binary
responses:
'200':
description: successful operation, name of the uploaded file
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/InformationPart'
components:
schemas:
InformationPart:
title: Dummy info
type: object
properties:
fileName:
type: string
additionalInformation:
type: string
with Array Files(Don't generate with Flux): default Mono multipartArray(Mono file, ServerWebExchange exchang
openapi-generator version
4.3.1
OpenAPI declaration file content or url
Command line used for generation
I use mvn clean install.
Steps to reproduce
When I generate with maven plugin for single part it's generating ok, problem is when it's generate for array object
I can resolve it changing in forms.mustache to {#isArray} to {#isListContainer} and it's works fine without changing version of plugin

Uploading multiple file with swagger api documentation and Spring Boot

I want to upload a list of files using swagger api and I can not find a way in which I get the endpoint generated having a list of MultipartFile. Could you please help me? I also searched in the swagger documentation without any luck. For now I have the following swagger config:
x-swagger-router-controller: attachments
post:
operationId: saveFiles
summary: saves the uploaded files
tags:
- files
consumes:
- multipart/form-data
produces:
- application/json
parameters:
- name: files
in: formData
type: array
items:
type: file
description: Files to be uploaded
required: true
- name: type
type: array
items:
type: string
description: File types
in: path
required: true
responses:
201:
description: Saved files
schema:
$ref: '#/definitions/CreatedFilesResponse'
415:
description: Unsupported media type
schema:
$ref: '#/definitions/ErrorResponse'
default:
description: Error
schema:
$ref: '#/definitions/ErrorResponse'
this code generates the following spring endpoint
public ResponseEntity<CreatedAttachmentsResponse> createFile(List<File> list, List<String> list1) {
return null;
}

Why does Spring Boot take so long to find method handler

I have a service configured using Spring Boot and Swagger.
My swagger paths config look like this:
paths:
/hello/test:
post:
summary: Hello World Test
description: >-
Hello World
operationId: helloTest
tags:
- Hello
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/HelloRequest'
description: Hello Request
required: true
responses:
'200':
description: >
OK
content:
application/json:
schema:
$ref: '#/components/schemas/HelloResponse'
'400':
$ref: '#/components/responses/BadRequest'
'401':
$ref: '#/components/responses/Unauthorized'
'403':
$ref: '#/components/responses/Forbidden'
'500':
$ref: '#/components/responses/InternalServerError'
/confirmations:
post:
summary: Hello World Confirmation
description: >-
Hello World Confirmation
operationId: postConfirmations
tags:
- Confirmation
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ConfirmationRequest'
description: Hello Confirmation Request
required: true
responses:
'204':
description: >
No Content
'400':
$ref: '#/components/responses/BadRequest'
'403':
$ref: '#/components/responses/Forbidden'
'500':
$ref: '#/components/responses/InternalServerError'
My logs keep showing this message several times
Did not find handler method for [/hello/test]
Even after this message is shown:
Returning handler method [public default org.springframework.http.ResponseEntity<com.sample.hello.generated.emvco.model.HelloResponse> com.sample.hello.generated.emvco.api.HelloApi.postTransactionCredentials(com.sample.hello.generated.emvco.model.HelloRequest)]
This takes up to 5 milliseconds of initial resolution which impacts the performance of the service. What causes spring to look repeatedly for one path which is clearly defined?
I think such a problem mainly comes when the structure of the project is not in the right way. I assume your controller class is not found or taking time during scanning cause it is in a package that will not be scanned by default. I guess your application is not in the right way or default structure. please change your controller to com.app.controller and check performance.

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)

Gets duplicated mapping key error using openapi 3.0

I am trying to define my APIs using openapi version 3.0.0. I've generated following YAML file:
openapi: 3.0.0
info:
title: My YAML
description: My YAML
version: 1.0.0
servers:
- url: http://my.server.url
paths:
/v1/service/uri:
post:
summary: Getting some information.
parameters:
- name: Content-Type
in: header
description: Content type of request body.
required: true
style: simple
explode: false
schema:
type: string
- name: Host
in: header
description: Originate host which returns the response.
required: false
style: simple
explode: false
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MyPostRequest'
example:
my_name: "zizi"
my_age: 29
required: true
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/MyPostResponse'
components:
schemas:
MyPostRequest:
type: object
properties:
my_name:
type: string
my_age:
type: integer
format: int32
MyPostResponse:
type: object
properties:
status:
type: integer
format: int32
When I copy/paste these lines into Swagger Editor, it gives me duplicated mapping key error on line 19; it is for section description of parameter Content-Type.
I have studied openapi documentation, but I didn't see anything wrong with my YAML file.
I am not sure why you get that error, I tried to find out in which language Swagger is written, as there are several YAML parsers out there that are known to have problems, but couldn't easily determine that using google or wikipedia.
You don't have any duplicate keys in your file, but it is invalid (i.e. not valid YAML) because of the indentation of the key content (the second occurrence, the one under paths →
/v1/service/uri → post → responses → 200), that should be aligned with
description as that key cannot have a value node that is both a scalar (OK) as well as a mapping node content: ....

Resources