Skip to content
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

Adding Example for FastApi OpenAPI documentation #715

Open
julien-roy-replicant opened this issue Mar 3, 2023 · 4 comments
Open

Adding Example for FastApi OpenAPI documentation #715

julien-roy-replicant opened this issue Mar 3, 2023 · 4 comments
Labels
kind/feature A request for a new feature. level/intermediate priority/medium topic: dx Improvements or issues relating to developer experience topic: generation

Comments

@julien-roy-replicant
Copy link

Problem

Currently for my pydantic models, I use the example field to document FastAPI:

= Field(..., example="This is my example for SwaggerUI")

Suggested solution

Would it be possible through comment in the schema.prisma to add these examples?

Alternatives

Open to any solution.

Additional context

I want to completely remove my custom pydantic object definitions and rely on your generated models and partials (which I find amazing!)

@RobertCraigie RobertCraigie added kind/feature A request for a new feature. level/intermediate priority/medium topic: dx Improvements or issues relating to developer experience topic: generation labels Mar 4, 2023
@RobertCraigie
Copy link
Owner

RobertCraigie commented Mar 4, 2023

Yeah this would be doable using triple-slash comments on your schema, e.g.

model User {
  /// @example("my example value")
  name String
}

Does that sound good to you?

@julien-roy-replicant
Copy link
Author

julien-roy-replicant commented Mar 6, 2023

Yes perfect!

Could that be generic enough to also include other pydantic arguments like min_length, regex, etc ?

@RobertCraigie
Copy link
Owner

Not with the proposed syntax but maybe it should be something like this instead?

model User {
  /// @pydantic.example("my example value") @pydantic.min_length(4)
  name String
}

Where the $ in the @pydantic.$() format is not validated and just passed straight through to pydantic.

@julien-roy-replicant
Copy link
Author

Yes, I really like this proposition :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A request for a new feature. level/intermediate priority/medium topic: dx Improvements or issues relating to developer experience topic: generation
Projects
Status: No status
Development

No branches or pull requests

2 participants