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

Hateoas option generate Links even for request or ErrorResponse

Open leccyril opened this issue 2 months ago • 2 comments

Bug Report Checklist

  • [yesy ] Have you provided a full/minimal spec to reproduce the issue?
  • [ yes] Have you validated the input using an OpenAPI validator (example)?
  • [ yes] Have you tested with the latest master to confirm the issue still exists?
  • [ yes] Have you searched for related issues/PRs?
  • [ ] What's the actual output vs expected output?

display links for error or input request

Expected: to not display links object and not inherit for error or input request.

Description

We are using HATEOAS with openapi generator for Springboot3 java 21, the issue is all object defined in the swagger.yaml are implementing the Link, problem, for Request or ErrorResponse we don,t want it, at least we don't want to write it on the documentation api image

openapi-generator version

7.4.0

OpenAPI declaration file content or url
   <configuration>
                            <inputSpec>${project.basedir}/swagger.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <library>spring-boot</library>
                            <apiPackage>com.openapi.generated</apiPackage>
                            <modelPackage>com.openapi.generated</modelPackage>
                            <supportingFilesToGenerate>false</supportingFilesToGenerate>
                            <configOptions>
                                <disallowAdditionalPropertiesIfNotPresent>false</disallowAdditionalPropertiesIfNotPresent>
                                <additionalModelTypeAnnotations>@lombok.Builder @lombok.AllArgsConstructor @lombok.EqualsAndHashCode(callSuper = true)
                                    @com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)
                                </additionalModelTypeAnnotations>
                                <hateoas>true</hateoas>
                                <reactive>true</reactive>
                                <interfaceOnly>true</interfaceOnly>
                                <skipDefaultInterface>true</skipDefaultInterface>
                                <useSpringBoot3>true</useSpringBoot3>
                                <useJakartaEe>true</useJakartaEe>
                            </configOptions>
                        </configuration>
openapi: '3.1.0'
info:
  version: 1.0.0
  title: open api generator
  termsOfService: http://swagger.io/terms/
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  contact:
    name: Support
    email: [email protected]
servers:
  - url: http://localhost:8081
    description: local
paths:
  /test:
    post:
      tags:
        - test
      summary: Create test
      description: Create test
      operationId: createTest
      requestBody:
        description: test object
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TestRequest'
        required: true
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /test/{id}:
    get:
      tags:
        - "test"
      summary: "get object"
      description: "Returns object"
      operationId: "getObject"
      parameters:
        - name: id
          in: path
          description: Gateway token generated in the network tokenization process
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Token not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    TestResponse:
      type: object
      properties:
        id:
          type: string
        value:
          type: string
    TestRequest:
      type: object
      properties:
        number:
          type: string
          description: The card number ex:1234 1234 1234 1243
    ErrorResponse:
      type: object
      properties:
        status:
          type: integer
          format: int32
          description: Request status
        type:
          type: string
          description: Error type
        code:
          type: string
          description: Error code
        errors:
          type: array
          items:
            type: string
            description: List of error messages
Generation Details
Steps to reproduce

Compile project, then launch it and connect on http://localhost:8082/swagger.html

Suggest a fix

Add parameter in the Object definition in yaml to specify if we want or not extends RepresentationModel<?>

repo : https://github.com/leccyril/openapi-generator

leccyril avatar Apr 23 '24 08:04 leccyril

any idea?

leccyril avatar May 08 '24 09:05 leccyril

@canadaduane any idea ?

leccyril avatar May 10 '24 10:05 leccyril