micronaut-projects / micronaut-openapi

Generates OpenAPI / Swagger Documentation for Micronaut projects
https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html
Apache License 2.0
80 stars 95 forks source link

Using OpenAPI annotations to create Swagger YAML for generics is not compatible with AWS #1646

Closed Gustl22 closed 3 months ago

Gustl22 commented 3 months ago

Feature description

From the AWS specs: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-known-issues.html#api-gateway-known-issues-rest-apis

Model names can only contain alphanumeric characters.

    @Get("/pageablelist")
    @Operation(responses = {@ApiResponse(responseCode = "200", useReturnTypeSchema = true)})
    @OffsetBasedPageableParameters
    public MyPageableListPage getMyPageableList(@Parameter (hidden = true) OffsetBasedPageable pageable) { /*...*/}

Which means, the generated schema:

# swagger.yml
components:
  schemas:
    MyPageableListPage:
      $ref: '#/components/schemas/OffsetBasedPage_SomeClazz_'
    OffsetBasedPage_SomeClazz_:
      ...

is not valid for AWS.

Which results in:

Value 'Errors found during import: Unable to create model for 'OffsetBasedPage_aaa_': Model name must be alphanumeric: OffsetBasedPage_aaa_
Unable to insert model 'aaaPage' due to an unsatisfied schema reference.

I tried to change the schemas naming via: https://micronaut-projects.github.io/micronaut-openapi/latest/guide/#schemasNaming

                        <arg>-J-Dmicronaut.openapi.property.naming.strategy=UPPER_CAMEL_CASE</arg>

but this only affects the properties and not the schemas.

Proposal:

So I propose to add the option to change the naming strategy for schemas, too:

micronaut.openapi.schema.naming.strategy=UPPER_CAMEL_CASE

Reference: https://stackoverflow.com/questions/37572531/amazon-api-gateway-import-from-swagger-error-not-taking-generics

altro3 commented 3 months ago

Added 3 new option to customize separators:

|`*micronaut.openapi.schema.name.separator.empty*` | If this property true, generic separators and inner class separators in schema name will be empty string. | Default: `false`
|`*micronaut.openapi.schema.name.separator.generic*` | System property that set generic class separator for schema name generation. | Default: `_`
|`*micronaut.openapi.schema.name.separator.inner-class*` | System property that set inner class separator for schema name generation. | Default: `.`

I think, it is enought