openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[REQ] Exclude hateoas from some schema objects

Open antonialatalo opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

The current implementation of Spring code generation with hateoas enabled creates models, that extends RepresentationModel. If we add for example some errors for HTTP 400 or 500, then as well they are extended by RepresentationModel The errors usually does not implement any hateoas, so they should not be extended.

En example of yaml

openapi: 3.0.1
info:
  title: Some API
  description: |-
    REST API for ...
  version: "1.0"
servers:
  - url: /some-api
tags:
  - name: SomeRoot
    description: Some Root services
paths:
  /:
    get:
      tags:
        - SomeRoot
      summary: Get some services
      description: |
        Some description
      operationId: listSomething
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SomeResource'
        401:
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        404:
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      deprecated: false

components:
  schemas:
    SomeResource:
      type: object
      title: SomeResource
    ErrorResponse:
      type: object
      title: ErrorResponse
      properties:
        code:
          type: string
          description: error code
        resaon:
          type: string
          description: error description

Currently generated pojo:

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2022-03-08T08:09:02.541357+02:00[Europe/Helsinki]")
public class ErrorResponse extends RepresentationModel<ErrorResponse>   {
...

Describe the solution you'd like

The solution is pretty easy. Just add new parameter like hateoasExclude that will contain schemas, that should not be extended by RepresentationModel. While generating in pojo.mustache, there should be checked per pojo, if this class should extend RepresentationModel

antonialatalo avatar Mar 08 '22 08:03 antonialatalo

Still no advancement for this since 2 years? because the issue is present event with request object, it make the api docu;entation really ugly, and on contract first it is really complicated

leccyril avatar Apr 23 '24 03:04 leccyril