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

Uncompilable java code when schema having properties #195

Closed beeondev closed 1 year ago

beeondev commented 1 year ago

Hi,

in the given my-test-case.ZIP , the openapi.yaml is valid, and the processor generates target files wiyhout complaining, but thoses files just not compiles.

The described endpoint (from YAML point of view) is a function expected a JSON body argument composed of 3 elements

But the processor does not generates anything in the model : class EndpointIdPostRequestBody not exists.

Best regards.

beeondev commented 1 year ago

Workaround seems to help the processor by providing explicit additional schema. Typically avoid to have raw inlined schema withing method, but rather declare explicit "component/schema/**" types.

Applying this rules (openapi.ZIP ), and the model compiles.

hauner commented 1 year ago

The processor generates only classes that are used in the api. It probably does not detect that the class is needed.

I guess this a bug. Looking at it.

hauner commented 1 year ago

so, it is not what I thought. What causes the issue is that the processor depends on the type attribute. Without it, it doesn't understand that the schema is an object and walks into the wrong code path.

adding type: object fixes the issue.

      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              # adding this repairs it
              type: object

Not sure If I can detect it without the type. I think type comes from JSON schema validation and is not required. Hmm, have to think about this :-)