OpenAPITools / OpenAPITools/openapi-generator

[BUG] [python-flask] Hosted UI doesn't match the openapi.json, missing readOnly information.

Open
#7,810 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

It seems like readOnly fields get dropped from the Swagger UI after generating the server stub.

The spec downlaoded from the server at /api/v3/openapi.json still holds the readOnly field, and it shows correctly in the public https://editor.swagger.io/ , but the Swagger UI hosted by the generated server doesn't respect it.

openapi-generator version

4.3.1

OpenAPI declaration file content or url

Start with https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
and set the following property:

    components:
      schemas:
        Pet:
          properties:
            id:
              readOnly: true
Steps to reproduce & generate
  1. Modify the above petstore.yaml file
  2. Generate a python-flask server: docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 generate --input-spec /local/petstore.yaml --generator-name python-flask --output /local
  3. Build & Run: docker build -t openapi_server ., docker run -p 8080:8080 openapi_server
  4. Visit http://localhost:8080/api/v3/ui/#/pet/add_pet. Switch to application/x-www-form-urlencoded. The id field is no longer readOnly- it appears in the Request Body Parameters.
  5. Download the /api/v3/openapi.json file from the UI, it still has the readOnly field, and it displays OK if pasted into https://editor.swagger.io/

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

Generate the modified petstore.yaml with the python-flask generator and inspect the hosted Swagger UI at /api/v3/ui/#/pet/add_pet. Compare the application/x-www-form-urlencoded request fields with /api/v3/openapi.json and the same specification in editor.swagger.io; done means the readOnly id field is treated consistently in the generated UI.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, openapi, python
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.