Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

ValidationError fail OpenAPI Schema validation #4855

Closed
9 tasks done
okamop opened this issue May 3, 2022 · 6 comments
Closed
9 tasks done

ValidationError fail OpenAPI Schema validation #4855

okamop opened this issue May 3, 2022 · 6 comments
Labels
question Question or problem question-migrate

Comments

@okamop
Copy link

okamop commented May 3, 2022

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    return {"message": "Hello World"}

Description

  • Running openapi-generator against the schema generated by FastAPI fails.
  • ValidationError schema cannot be processed.
  • Generation fails with FastAPI v0.75.0 or higher
  • Generated successfully with FastAPI v0.74.1
$ openapi-generator-cli generate -g typescript-axios -i http://localhost:8000/openapi.json

[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: typescript-axios (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'typescript-axios' is considered stable.
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Hint: Environment variable 'TS_POST_PROCESS_FILE' (optional) not defined. E.g. to format the source code, please try 'export TS_POST_PROCESS_FILE="/usr/local/bin/prettier --write"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractTypeScriptClientCodegen - Note: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] WARN  o.o.c.l.AbstractTypeScriptClientCodegen - The import is a union type. Consider using the toModelImportMap method.
Exception in thread "main" java.lang.RuntimeException: Could not process model 'ValidationError'.Please make sure that your schema is correct!
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:492)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:888)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:441)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.StringIndexOutOfBoundsException: begin 1, end 0, length 0
        at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3751)
        at java.base/java.lang.String.substring(String.java:1907)
        at java.base/java.lang.String.substring(String.java:1880)
        at org.openapitools.codegen.languages.TypeScriptAxiosClientCodegen.postProcessModels(TypeScriptAxiosClientCodegen.java:233)
        at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1302)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:487)
        ... 4 more

Process finished with exit code 1

Operating System

macOS

Operating System Details

No response

FastAPI Version

0.75.2

Python Version

3.10.4

Additional Context

No response

@okamop okamop added the question Question or problem label May 3, 2022
@andvikt
Copy link

andvikt commented May 8, 2022

same on 0.76.0

@vhuliai-beetroot
Copy link

Same on 0.77.1

@flxdot
Copy link

flxdot commented May 16, 2022

Well, it is due to this change: #4806

But I would rather argue this is an issue of openapi-generator, as the schema is valid according to the specification of OpenAPI. There is even an open issue for that: OpenAPITools/openapi-generator#4576

@okamop
Copy link
Author

okamop commented May 16, 2022

Well, it is due to this change: #4806

But I would rather argue this is an issue of openapi-generator, as the schema is valid according to the specification of OpenAPI. There is even an open issue for that: OpenAPITools/openapi-generator#4576

It seems so.
I used openapi-typescript instead.
This one generates without any problem.

Close this issue.

@okamop okamop closed this as completed May 16, 2022
@bykof
Copy link

bykof commented May 18, 2022

I used the typescript-fetch generator and it worked.

@gaganpreet
Copy link

gaganpreet commented May 23, 2022

This issue with typescript-axios generator is fixed in the main branch of openapi generator, but it's not packaged yet. Using git bisect I pinned the fix down to this commit

Edit: Downgrading to 5.3.x also works.

@tiangolo tiangolo reopened this Feb 27, 2023
Repository owner locked and limited conversation to collaborators Feb 27, 2023
@tiangolo tiangolo converted this issue into discussion #6387 Feb 27, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Question or problem question-migrate
Projects
None yet
Development

No branches or pull requests

7 participants