Skip to content

[BUG][DefaultCodegen] allOf not respecting readOnly and all #10895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
4 of 6 tasks
laDanz opened this issue Nov 19, 2021 · 0 comments
Open
4 of 6 tasks

[BUG][DefaultCodegen] allOf not respecting readOnly and all #10895

laDanz opened this issue Nov 19, 2021 · 0 comments

Comments

@laDanz
Copy link

laDanz commented Nov 19, 2021

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I try to use a enum property, but override readOnly attribute (same for description, and all others), but it is not working.
I only noticed, because I'm having my own template script (not related to this problem!) to not generate @NotNull anotation in case of required but readOnly attribut, like here: #9655

This is the proposed way of dealing with readOnly consider by OpenAPI spec / JSON schema, see:

openapi-generator version

latest version, master.

OpenAPI declaration file content or url

File src/test/resources/3_0/allOf-readonly.yaml

openapi: 3.0.1
info:
  version: 1.0.0
  title: Example
  license:
    name: MIT
servers:
  - url: http://api.example.xyz/v1
paths:
  /person/display/{personId}:
    get:
      parameters:
        - name: personId
          in: path
          required: true
          description: The id of the person to retrieve
          schema:
            type: string
      operationId: list
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/clubForCreation"
components:
  schemas:
    ClubType:
      type: string
      enum:
        - serious
        - silly

    clubForCreation:
      properties:
        type:
          $ref: '#/components/schemas/ClubType'

    clubForUpdate:
      properties:
        type:
          allOf:
            - $ref: '#/components/schemas/ClubType'
            - readOnly: true
Generation Details
Steps to reproduce

Test for DefaultCodegenTest

    public void testAllOfReadonly() {
        final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOf-readonly.yaml");
        DefaultCodegen codegen = new DefaultCodegen();

        // OK
        Schema clubForCreation = openAPI.getComponents().getSchemas().get("clubForCreation");//clubForCreation.getProperties().get("type")).getReadOnly() is null
        CodegenProperty clubForCreationType = codegen.fromProperty("type", clubForCreation);

        Assert.assertEquals(clubForCreationType.isReadOnly, false);

        // NOK
        Schema clubForUpdate = openAPI.getComponents().getSchemas().get("clubForUpdate");// clubForUpdate.getProperties().get("type")).getReadOnly() is null
        CodegenProperty clubForUpdateType = codegen.fromProperty("type", clubForUpdate);

        Assert.assertEquals(clubForUpdateType.isReadOnly, true);
    }
Related issues/PRs
Suggest a fix

When a property is a ComposedSchema (espacially an "allOf") it should sync/merge all readOnly / description / ... values...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant