openapi-processor / openapi-processor-spring

an OpenAPI 3.0 & 3.1 interface & model java code generator for Spring Boot
https://docs.openapiprocessor.io
Apache License 2.0
40 stars 9 forks source link

[fix included] produces / consumes mapping is generated multiple times #126

Closed JonasGroeger closed 3 years ago

JonasGroeger commented 3 years ago

There must be a distinct filter applied to the produces and consumes mappings since otherwise it generates the following structure:

    @GetMapping(
            path = "/destinations",
            produces = {
                "application/json",
                "application/json",
                "application/json",
                "application/json"
            })
    ResponseEntity<?> getAllDestinations();

from this yaml:

paths:
    '/destinations':
        get:
            responses:
                '200':
                    description: OK
                    content:
                        application/json:
                            schema:
                                '$ref': '#/components/schemas/GetAllDestinationsResponse'
                '400':
                    description: Bad Request
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ErrorResponse'
                '401':
                    description: Unauthorized
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ErrorResponse'
                '403':
                    description: Forbidden
                    content:
                        application/json:
                            schema:
                                $ref: '#/components/schemas/ErrorResponse'

Fix:

https://github.com/openapi-processor/openapi-processor-spring/blob/b6cc315f3d08d0f7f7c40162faf0e86b77d6e047/src/main/kotlin/io/openapiprocessor/spring/writer/java/MappingAnnotationWriter.kt#L46

mapping +=  consumes.map {
    quote(it)
}.distinct().joinToString(", ")

https://github.com/openapi-processor/openapi-processor-spring/blob/b6cc315f3d08d0f7f7c40162faf0e86b77d6e047/src/main/kotlin/io/openapiprocessor/spring/writer/java/MappingAnnotationWriter.kt#L57

mapping +=  produces.map {
    quote(it)
}.distinct().joinToString(", ")
hauner commented 3 years ago

yes, the example makes the missing distinct quite obvious 🤨

Thanks for reporting.

hauner commented 3 years ago

fixed & published in 2021.3.1