OpenAPITools / OpenAPITools/openapi-generator

[REQ] Exclude hateoas from some schema objects

Open
#11,828 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Spring code generator and its pojo.mustache template, then trace how generator parameters reach per-schema model generation. Use the provided OpenAPI example to verify that an option such as hateoasExclude prevents ErrorResponse from extending RepresentationModel while SomeResource still does. The issue does not name a test file, so identify the relevant generator test before making changes.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.