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

feat(spec2sdk): render simple types as Pydantic RootModel #2

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

catcombo
Copy link
Contributor

@catcombo catcombo commented Sep 4, 2024

Reviewer

  • for your information
  • process and function, acceptance criteria
  • implementation (code design, correctness, formatting)
    • unit tests are implemented
    • E2E tests are implemented, if reasonable
  • testing
    • checklist of test cases for manual testing is created
    • all test cases are passed successfully
    • invariants are checked (what should stay the same or not be affected by the changes)

Description

The example is copied from Softfair customer spec:

paths:
  /dokument/get/data:
    post:
      operationId: GetDokumente
      requestBody:
        description: Liste der auszulesenden Dokumente
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DokumentIDs'
      responses:
        '200':
          description: Successful response

components:
  schemas:
    DokumentIDs:
      type: array
      items:
        type: integer
        format: int32

spec2sdk generates a model DokumentIDs: TypeAlias = list[int] that will be used as a type for parameter in the get_dokumente method:
image
But the type of the field doesn't meet HTTPClient requirements for the body field. It must be a BaseModel to be serializable. This PR makes simple types serializable. New model will be DokumentIDs = RootModel[list[int]] and can be serialized.

@mm-matthias
Copy link

You really know a lot of pydantic magics now.

@catcombo
Copy link
Contributor Author

catcombo commented Sep 5, 2024

You really know a lot of pydantic magics now.

This is just a scratch on the surface :)

@catcombo catcombo merged commit 2cfaf7d into master Sep 5, 2024
3 checks passed
@catcombo catcombo deleted the feature/render-simple-types-as-root-model branch September 5, 2024 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants