openapi yaml つかってみた

★★

:/var/www/html/demo5# ls
openapi.yaml
:/var/www/html/demo5# fastapi-codegen    --input openapi.yaml --output output --generate-routers --model-file models.py
:/var/www/html/demo5# ls
openapi.yaml  output
:/var/www/html/demo5# ls -l output
total 16
-rw-r--r-- 1 root root  347 Jan  2 04:42 dependencies.py
-rw-r--r-- 1 root root 1699 Jan  2 04:42 main.py
-rw-r--r-- 1 root root 2700 Jan  2 04:42 models.py
drwxr-xr-x 2 root root 4096 Jan  2 04:42 routers
:/var/www/html/demo5# 
:/var/www/html/demo5# datamodel-codegen  --input openapi.yaml --input-file-type openapi --output ./output/schemas.py
:/var/www/html/demo5# 
:/var/www/html/demo5# ls -l output
total 20
-rw-r--r-- 1 root root  347 Jan  2 04:42 dependencies.py
-rw-r--r-- 1 root root 1699 Jan  2 04:42 main.py
-rw-r--r-- 1 root root 2700 Jan  2 04:42 models.py
drwxr-xr-x 2 root root 4096 Jan  2 04:42 routers
-rw-r--r-- 1 root root 2418 Jan  2 04:42 schemas.py
:/var/www/html/demo5# 

 

 
★openapi.yaml
 
     1 openapi: 3.0.3
     2 info:
     3   title: Swagger Petstore - OpenAPI 3.0
     4   description: |-
     5     This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
     6     Swagger at https://swagger.io(https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
     7     You can now help us improve the API whether it's by making changes to the definition itself or to the code.
     8     That way, with time, we can improve the API in general, and expose some of the new features in OAS3.
     9
    10     _If you're looking for the Swagger 2.0/OAS 2.0 version of Petstore, then click [here](https://editor.swagger.io/?url=https://petstore.swagger.io/v2/swagger.yaml). Alternatively, you can load via the `Edit > Load Petstore OAS 2.0` menu option!_
    11     
    12     Some useful links:
    13     - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
    15   termsOfService: http://swagger.io/terms/
    16   contact:
    17     email: apiteam@swagger.io
    18   license:
    19     name: Apache 2.0
    21   version: 1.0.11
    22 externalDocs:
    23   description: Find out more about Swagger
    24   url: http://swagger.io
    25 servers:
    27 tags:
    28   - name: pet
    29     description: Everything about your Pets
    30     externalDocs:
    31       description: Find out more
    32       url: http://swagger.io
    33   - name: store
    34     description: Access to Petstore orders
    35     externalDocs:
    36       description: Find out more about our store
    37       url: http://swagger.io
    38   - name: user
    39     description: Operations about user
    40 paths:
    41   /pet:
    42     put:
    43       tags:
    44         - pet
    45       summary: Update an existing pet
    46       description: Update an existing pet by Id
    47       operationId: updatePet
    48       requestBody:
    49         description: Update an existent pet in the store
    50         content:
    51           application/json:
    52             schema:
    53               $ref: '#/components/schemas/Pet'
    54           application/xml:
    55             schema:
    56               $ref: '#/components/schemas/Pet'
    57           application/x-www-form-urlencoded:
    58             schema:
    59               $ref: '#/components/schemas/Pet'
    60         required: true
    61       responses:
    62         '200':
    63           description: Successful operation
    64           content:
    65             application/json:
    66               schema:
    67                 $ref: '#/components/schemas/Pet'          
    68             application/xml:
    69               schema:
    70                 $ref: '#/components/schemas/Pet'
    71         '400':
    72           description: Invalid ID supplied
    73         '404':
    74           description: Pet not found
    75         '405':
    76           description: Validation exception
    77       security:
    78         - petstore_auth:
    79             - write:pets
    80             - read:pets
    81     post:
    82       tags:
    83         - pet
    84       summary: Add a new pet to the store
    85       description: Add a new pet to the store
    86       operationId: addPet
    87       requestBody:
    88         description: Create a new pet in the store
    89         content:
    90           application/json:
    91             schema:
    92               $ref: '#/components/schemas/Pet'
    93           application/xml:
    94             schema:
    95               $ref: '#/components/schemas/Pet'
    96           application/x-www-form-urlencoded:
    97             schema:
    98               $ref: '#/components/schemas/Pet'
    99         required: true
   100       responses:
   101         '200':
   102           description: Successful operation
   103           content:
   104             application/json:
   105               schema:
   106                 $ref: '#/components/schemas/Pet'          
   107             application/xml:
   108               schema:
   109                 $ref: '#/components/schemas/Pet'
   110         '405':
   111           description: Invalid input
   112       security:
   113         - petstore_auth:
   114             - write:pets
   115             - read:pets
   116   /pet/findByStatus:
   117     get:
   118       tags:
   119         - pet
   120       summary: Finds Pets by status
   121       description: Multiple status values can be provided with comma separated strings
   122       operationId: findPetsByStatus
   123       parameters:
   124         - name: status
   125           in: query
   126           description: Status values that need to be considered for filter
   127           required: false
   128           explode: true
   129           schema:
   130             type: string
   131             default: available
   132             enum:
   133               - available
   134               - pending
   135               - sold
   136       responses:
   137         '200':
   138           description: successful operation
   139           content:
   140             application/json:
   141               schema:
   142                 type: array
   143                 items:
   144                   $ref: '#/components/schemas/Pet'          
   145             application/xml:
   146               schema:
   147                 type: array
   148                 items:
   149                   $ref: '#/components/schemas/Pet'
   150         '400':
   151           description: Invalid status value
   152       security:
   153         - petstore_auth:
   154             - write:pets
   155             - read:pets
   156   /pet/findByTags:
   157     get:
   158       tags:
   159         - pet
   160       summary: Finds Pets by tags
   161       description: Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
   162       operationId: findPetsByTags
   163       parameters:
   164         - name: tags
   165           in: query
   166           description: Tags to filter by
   167           required: false
   168           explode: true
   169           schema:
   170             type: array
   171             items:
   172               type: string
   173       responses:
   174         '200':
   175           description: successful operation
   176           content:
   177             application/json:
   178               schema:
   179                 type: array
   180                 items:
   181                   $ref: '#/components/schemas/Pet'          
   182             application/xml:
   183               schema:
   184                 type: array
   185                 items:
   186                   $ref: '#/components/schemas/Pet'
   187         '400':
   188           description: Invalid tag value
   189       security:
   190         - petstore_auth:
   191             - write:pets
   192             - read:pets
   193   /pet/{petId}:
   194     get:
   195       tags:
   196         - pet
   197       summary: Find pet by ID
   198       description: Returns a single pet
   199       operationId: getPetById
   200       parameters:
   201         - name: petId
   202           in: path
   203           description: ID of pet to return
   204           required: true
   205           schema:
   206             type: integer
   207             format: int64
   208       responses:
   209         '200':
   210           description: successful operation
   211           content:
   212             application/json:
   213               schema:
   214                 $ref: '#/components/schemas/Pet'          
   215             application/xml:
   216               schema:
   217                 $ref: '#/components/schemas/Pet'
   218         '400':
   219           description: Invalid ID supplied
   220         '404':
   221           description: Pet not found
   222       security:
   223         - api_key:
   224         - petstore_auth:
   225             - write:pets
   226             - read:pets
   227     post:
   228       tags:
   229         - pet
   230       summary: Updates a pet in the store with form data
   231       description: ''
   232       operationId: updatePetWithForm
   233       parameters:
   234         - name: petId
   235           in: path
   236           description: ID of pet that needs to be updated
   237           required: true
   238           schema:
   239             type: integer
   240             format: int64
   241         - name: name
   242           in: query
   243           description: Name of pet that needs to be updated
   244           schema:
   245             type: string
   246         - name: status
   247           in: query
   248           description: Status of pet that needs to be updated
   249           schema:
   250             type: string
   251       responses:
   252         '405':
   253           description: Invalid input
   254       security:
   255         - petstore_auth:
   256             - write:pets
   257             - read:pets
   258     delete:
   259       tags:
   260         - pet
   261       summary: Deletes a pet
   262       description: delete a pet
   263       operationId: deletePet
   264       parameters:
   265         - name: api_key
   266           in: header
   267           description: ''
   268           required: false
   269           schema:
   270             type: string
   271         - name: petId
   272           in: path
   273           description: Pet id to delete
   274           required: true
   275           schema:
   276             type: integer
   277             format: int64
   278       responses:
   279         '400':
   280           description: Invalid pet value
   281       security:
   282         - petstore_auth:
   283             - write:pets
   284             - read:pets
   285   /pet/{petId}/uploadImage:
   286     post:
   287       tags:
   288         - pet
   289       summary: uploads an image
   290       description: ''
   291       operationId: uploadFile
   292       parameters:
   293         - name: petId
   294           in: path
   295           description: ID of pet to update
   296           required: true
   297           schema:
   298             type: integer
   299             format: int64
   300         - name: additionalMetadata
   301           in: query
   302           description: Additional Metadata
   303           required: false
   304           schema:
   305             type: string
   306       requestBody:
   307         content:
   308           application/octet-stream:
   309             schema:
   310               type: string
   311               format: binary
   312       responses:
   313         '200':
   314           description: successful operation
   315           content:
   316             application/json:
   317               schema:
   318                 $ref: '#/components/schemas/ApiResponse'
   319       security:
   320         - petstore_auth:
   321             - write:pets
   322             - read:pets
   323   /store/inventory:
   324     get:
   325       tags:
   326         - store
   327       summary: Returns pet inventories by status
   328       description: Returns a map of status codes to quantities
   329       operationId: getInventory
   330       responses:
   331         '200':
   332           description: successful operation
   333           content:
   334             application/json:
   335               schema:
   336                 type: object
   337                 additionalProperties:
   338                   type: integer
   339                   format: int32
   340       security:
   341         - api_key:
   342   /store/order:
   343     post:
   344       tags:
   345         - store
   346       summary: Place an order for a pet
   347       description: Place a new order in the store
   348       operationId: placeOrder
   349       requestBody:
   350         content:
   351           application/json:
   352             schema:
   353               $ref: '#/components/schemas/Order'
   354           application/xml:
   355             schema:
   356               $ref: '#/components/schemas/Order'
   357           application/x-www-form-urlencoded:
   358             schema:
   359               $ref: '#/components/schemas/Order'
   360       responses:
   361         '200':
   362           description: successful operation
   363           content:
   364             application/json:
   365               schema:
   366                 $ref: '#/components/schemas/Order'
   367         '405':
   368           description: Invalid input
   369   /store/order/{orderId}:
   370     get:
   371       tags:
   372         - store
   373       summary: Find purchase order by ID
   374       description: For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions.
   375       operationId: getOrderById
   376       parameters:
   377         - name: orderId
   378           in: path
   379           description: ID of order that needs to be fetched
   380           required: true
   381           schema:
   382             type: integer
   383             format: int64
   384       responses:
   385         '200':
   386           description: successful operation
   387           content:
   388             application/json:
   389               schema:
   390                 $ref: '#/components/schemas/Order'          
   391             application/xml:
   392               schema:
   393                 $ref: '#/components/schemas/Order'
   394         '400':
   395           description: Invalid ID supplied
   396         '404':
   397           description: Order not found
   398     delete:
   399       tags:
   400         - store
   401       summary: Delete purchase order by ID
   402       description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
   403       operationId: deleteOrder
   404       parameters:
   405         - name: orderId
   406           in: path
   407           description: ID of the order that needs to be deleted
   408           required: true
   409           schema:
   410             type: integer
   411             format: int64
   412       responses:
   413         '400':
   414           description: Invalid ID supplied
   415         '404':
   416           description: Order not found
   417   /user:
   418     post:
   419       tags:
   420         - user
   421       summary: Create user
   422       description: This can only be done by the logged in user.
   423       operationId: createUser
   424       requestBody:
   425         description: Created user object
   426         content:
   427           application/json:
   428             schema:
   429               $ref: '#/components/schemas/User'
   430           application/xml:
   431             schema:
   432               $ref: '#/components/schemas/User'
   433           application/x-www-form-urlencoded:
   434             schema:
   435               $ref: '#/components/schemas/User'
   436       responses:
   437         default:
   438           description: successful operation
   439           content:
   440             application/json:
   441               schema:
   442                 $ref: '#/components/schemas/User'
   443             application/xml:
   444               schema:
   445                 $ref: '#/components/schemas/User'
   446   /user/createWithList:
   447     post:
   448       tags:
   449         - user
   450       summary: Creates list of users with given input array
   451       description: Creates list of users with given input array
   452       operationId: createUsersWithListInput
   453       requestBody:
   454         content:
   455           application/json:
   456             schema:
   457               type: array
   458               items:
   459                 $ref: '#/components/schemas/User'
   460       responses:
   461         '200':
   462           description: Successful operation
   463           content:
   464             application/json:
   465               schema:
   466                 $ref: '#/components/schemas/User'          
   467             application/xml:
   468               schema:
   469                 $ref: '#/components/schemas/User'
   470         default:
   471           description: successful operation
   472   /user/login:
   473     get:
   474       tags:
   475         - user
   476       summary: Logs user into the system
   477       description: ''
   478       operationId: loginUser
   479       parameters:
   480         - name: username
   481           in: query
   482           description: The user name for login
   483           required: false
   484           schema:
   485             type: string
   486         - name: password
   487           in: query
   488           description: The password for login in clear text
   489           required: false
   490           schema:
   491             type: string
   492       responses:
   493         '200':
   494           description: successful operation
   495           headers:
   496             X-Rate-Limit:
   497               description: calls per hour allowed by the user
   498               schema:
   499                 type: integer
   500                 format: int32
   501             X-Expires-After:
   502               description: date in UTC when token expires
   503               schema:
   504                 type: string
   505                 format: date-time
   506           content:
   507             application/xml:
   508               schema:
   509                 type: string
   510             application/json:
   511               schema:
   512                 type: string
   513         '400':
   514           description: Invalid username/password supplied
   515   /user/logout:
   516     get:
   517       tags:
   518         - user
   519       summary: Logs out current logged in user session
   520       description: ''
   521       operationId: logoutUser
   522       parameters: []
   523       responses:
   524         default:
   525           description: successful operation
   526   /user/{username}:
   527     get:
   528       tags:
   529         - user
   530       summary: Get user by user name
   531       description: ''
   532       operationId: getUserByName
   533       parameters:
   534         - name: username
   535           in: path
   536           description: 'The name that needs to be fetched. Use user1 for testing. '
   537           required: true
   538           schema:
   539             type: string
   540       responses:
   541         '200':
   542           description: successful operation
   543           content:
   544             application/json:
   545               schema:
   546                 $ref: '#/components/schemas/User'          
   547             application/xml:
   548               schema:
   549                 $ref: '#/components/schemas/User'
   550         '400':
   551           description: Invalid username supplied
   552         '404':
   553           description: User not found
   554     put:
   555       tags:
   556         - user
   557       summary: Update user
   558       description: This can only be done by the logged in user.
   559       operationId: updateUser
   560       parameters:
   561         - name: username
   562           in: path
   563           description: name that need to be deleted
   564           required: true
   565           schema:
   566             type: string
   567       requestBody:
   568         description: Update an existent user in the store
   569         content:
   570           application/json:
   571             schema:
   572               $ref: '#/components/schemas/User'
   573           application/xml:
   574             schema:
   575               $ref: '#/components/schemas/User'
   576           application/x-www-form-urlencoded:
   577             schema:
   578               $ref: '#/components/schemas/User'
   579       responses:
   580         default:
   581           description: successful operation
   582     delete:
   583       tags:
   584         - user
   585       summary: Delete user
   586       description: This can only be done by the logged in user.
   587       operationId: deleteUser
   588       parameters:
   589         - name: username
   590           in: path
   591           description: The name that needs to be deleted
   592           required: true
   593           schema:
   594             type: string
   595       responses:
   596         '400':
   597           description: Invalid username supplied
   598         '404':
   599           description: User not found
   600 components:
   601   schemas:
   602     Order:
   603       type: object
   604       properties:
   605         id:
   606           type: integer
   607           format: int64
   608           example: 10
   609         petId:
   610           type: integer
   611           format: int64
   612           example: 198772
   613         quantity:
   614           type: integer
   615           format: int32
   616           example: 7
   617         shipDate:
   618           type: string
   619           format: date-time
   620         status:
   621           type: string
   622           description: Order Status
   623           example: approved
   624           enum:
   625             - placed
   626             - approved
   627             - delivered
   628         complete:
   629           type: boolean
   630       xml:
   631         name: order
   632     Customer:
   633       type: object
   634       properties:
   635         id:
   636           type: integer
   637           format: int64
   638           example: 100000
   639         username:
   640           type: string
   641           example: fehguy
   642         address:
   643           type: array
   644           xml:
   645             name: addresses
   646             wrapped: true
   647           items:
   648             $ref: '#/components/schemas/Address'
   649       xml:
   650         name: customer
   651     Address:
   652       type: object
   653       properties:
   654         street:
   655           type: string
   656           example: 437 Lytton
   657         city:
   658           type: string
   659           example: Palo Alto
   660         state:
   661           type: string
   662           example: CA
   663         zip:
   664           type: string
   665           example: '94301'
   666       xml:
   667         name: address
   668     Category:
   669       type: object
   670       properties:
   671         id:
   672           type: integer
   673           format: int64
   674           example: 1
   675         name:
   676           type: string
   677           example: Dogs
   678       xml:
   679         name: category
   680     User:
   681       type: object
   682       properties:
   683         id:
   684           type: integer
   685           format: int64
   686           example: 10
   687         username:
   688           type: string
   689           example: theUser
   690         firstName:
   691           type: string
   692           example: John
   693         lastName:
   694           type: string
   695           example: James
   696         email:
   697           type: string
   698           example: john@email.com
   699         password:
   700           type: string
   701           example: '12345'
   702         phone:
   703           type: string
   704           example: '12345'
   705         userStatus:
   706           type: integer
   707           description: User Status
   708           format: int32
   709           example: 1
   710       xml:
   711         name: user
   712     Tag:
   713       type: object
   714       properties:
   715         id:
   716           type: integer
   717           format: int64
   718         name:
   719           type: string
   720       xml:
   721         name: tag
   722     Pet:
   723       required:
   724         - name
   725         - photoUrls
   726       type: object
   727       properties:
   728         id:
   729           type: integer
   730           format: int64
   731           example: 10
   732         name:
   733           type: string
   734           example: doggie
   735         category:
   736           $ref: '#/components/schemas/Category'
   737         photoUrls:
   738           type: array
   739           xml:
   740             wrapped: true
   741           items:
   742             type: string
   743             xml:
   744               name: photoUrl
   745         tags:
   746           type: array
   747           xml:
   748             wrapped: true
   749           items:
   750             $ref: '#/components/schemas/Tag'
   751         status:
   752           type: string
   753           description: pet status in the store
   754           enum:
   755             - available
   756             - pending
   757             - sold
   758       xml:
   759         name: pet
   760     ApiResponse:
   761       type: object
   762       properties:
   763         code:
   764           type: integer
   765           format: int32
   766         type:
   767           type: string
   768         message:
   769           type: string
   770       xml:
   771         name: '##default'
   772   requestBodies:
   773     Pet:
   774       description: Pet object that needs to be added to the store
   775       content:
   776         application/json:
   777           schema:
   778             $ref: '#/components/schemas/Pet'
   779         application/xml:
   780           schema:
   781             $ref: '#/components/schemas/Pet'
   782     UserArray:
   783       description: List of user object
   784       content:
   785         application/json:
   786           schema:
   787             type: array
   788             items:
   789               $ref: '#/components/schemas/User'
   790   securitySchemes:
   791     petstore_auth:
   792       type: oauth2
   793       flows:
   794         implicit:
   795           authorizationUrl: https://petstore3.swagger.io/oauth/authorize
   796           scopes:
   797             write:pets: modify pets in your account
   798             read:pets: read your pets
   799     api_key:
   800       type: apiKey
   801       name: api_key
   802       in: header
   803
 
 
★output/dependencies.py
     1 # generated by fastapi-codegen:
     2 #   filename:  openapi.yaml
     3 #   timestamp: 2024-01-02T04:42:03+00:00
     4
     5 from __future__ import annotations
     6
     7 from typing import List, Optional, Union
     8
     9 from fastapi import Path, Query, Request
    10 from starlette.requests import Request
    11
    12 from .models import ApiResponse, Order, Pet, Status3, StoreInventoryGetResponse, User
 
 
 
★ output/main.py
    13 # generated by fastapi-codegen:
    14 #   filename:  openapi.yaml
    15 #   timestamp: 2024-01-02T04:42:03+00:00
    16
    17 from __future__ import annotations
    18
    19 from fastapi import FastAPI
    20
    21 from .routers import pet, store, user
    22
    23 app = FastAPI(
    24     title='Swagger Petstore - OpenAPI 3.0',
    25     description="This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about\nSwagger at https://swagger.io(https://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\n_If you're looking for the Swagger 2.0/OAS 2.0 version of Petstore, then click [here](https://editor.swagger.io/?url=https://petstore.swagger.io/v2/swagger.yaml). Alternatively, you can load via the `Edit > Load Petstore OAS 2.0` menu option!_\n\nSome useful links:\n- [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)\n- [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)",
    26     termsOfService='http://swagger.io/terms/',
    27     contact={'email': 'apiteam@swagger.io'},
    28     license={
    29         'name': 'Apache 2.0',
    31     },
    32     version='1.0.11',
    33     servers=[{'url': 'https://petstore3.swagger.io/api/v3'}],
    34 )
    35
    36 app.include_router(pet.router)
    37 app.include_router(store.router)
    38 app.include_router(user.router)
    39
    40
    41 @app.get("/")
    42 async def root():
    43     return {"message": "Gateway of the App"}
 
 
★output/models.py
    44 # generated by fastapi-codegen:
    45 #   filename:  openapi.yaml
    46 #   timestamp: 2024-01-02T04:42:03+00:00
    47
    48 from __future__ import annotations
    49
    50 from datetime import datetime
    51 from enum import Enum
    52 from typing import Dict, List, Optional
    53
    54 from pydantic import BaseModel, Field
    55
    56
    57 class Status(Enum):
    58     placed = 'placed'
    59     approved = 'approved'
    60     delivered = 'delivered'
    61
    62
    63 class Order(BaseModel):
    64     id: Optional[int] = Field(None, example=10)
    65     petId: Optional[int] = Field(None, example=198772)
    66     quantity: Optional[int] = Field(None, example=7)
    67     shipDate: Optional[datetime] = None
    68     status: Optional[Status] = Field(
    69         None, description='Order Status', example='approved'
    70     )
    71     complete: Optional[bool] = None
    72
    73
    74 class Address(BaseModel):
    75     street: Optional[str] = Field(None, example='437 Lytton')
    76     city: Optional[str] = Field(None, example='Palo Alto')
    77     state: Optional[str] = Field(None, example='CA')
    78     zip: Optional[str] = Field(None, example='94301')
    79
    80
    81 class Category(BaseModel):
    82     id: Optional[int] = Field(None, example=1)
    83     name: Optional[str] = Field(None, example='Dogs')
    84
    85
    86 class User(BaseModel):
    87     id: Optional[int] = Field(None, example=10)
    88     username: Optional[str] = Field(None, example='theUser')
    89     firstName: Optional[str] = Field(None, example='John')
    90     lastName: Optional[str] = Field(None, example='James')
    91     email: Optional[str] = Field(None, example='john@email.com')
    92     password: Optional[str] = Field(None, example='12345')
    93     phone: Optional[str] = Field(None, example='12345')
    94     userStatus: Optional[int] = Field(None, description='User Status', example=1)
    95
    96
    97 class Tag(BaseModel):
    98     id: Optional[int] = None
    99     name: Optional[str] = None
   100
   101
   102 class Status1(Enum):
   103     available = 'available'
   104     pending = 'pending'
   105     sold = 'sold'
   106
   107
   108 class Pet(BaseModel):
   109     id: Optional[int] = Field(None, example=10)
   110     name: str = Field(..., example='doggie')
   111     category: Optional[Category] = None
   112     photoUrls: List[str]
   113     tags: Optional[List[Tag]] = None
   114     status: Optional[Status1] = Field(None, description='pet status in the store')
   115
   116
   117 class ApiResponse(BaseModel):
   118     code: Optional[int] = None
   119     type: Optional[str] = None
   120     message: Optional[str] = None
   121
   122
   123 class Status2(Enum):
   124     available = 'available'
   125     pending = 'pending'
   126     sold = 'sold'
   127
   128
   129 class Status3(Enum):
   130     available = 'available'
   131     pending = 'pending'
   132     sold = 'sold'
   133
   134
   135 class StoreInventoryGetResponse(BaseModel):
   136     __root__: Optional[Dict[str, int]] = None
   137
   138
   139 class Customer(BaseModel):
   140     id: Optional[int] = Field(None, example=100000)
   141     username: Optional[str] = Field(None, example='fehguy')
   142     address: Optional[List[Address]] = None
 
 
 
★output/schemas.py
   143 # generated by datamodel-codegen:
   144 #   filename:  openapi.yaml
   145 #   timestamp: 2024-01-02T04:42:23+00:00
   146
   147 from __future__ import annotations
   148
   149 from datetime import datetime
   150 from enum import Enum
   151 from typing import List, Optional
   152
   153 from pydantic import BaseModel, Field
   154
   155
   156 class Status(Enum):
   157     placed = 'placed'
   158     approved = 'approved'
   159     delivered = 'delivered'
   160
   161
   162 class Order(BaseModel):
   163     id: Optional[int] = Field(None, example=10)
   164     petId: Optional[int] = Field(None, example=198772)
   165     quantity: Optional[int] = Field(None, example=7)
   166     shipDate: Optional[datetime] = None
   167     status: Optional[Status] = Field(
   168         None, description='Order Status', example='approved'
   169     )
   170     complete: Optional[bool] = None
   171
   172
   173 class Address(BaseModel):
   174     street: Optional[str] = Field(None, example='437 Lytton')
   175     city: Optional[str] = Field(None, example='Palo Alto')
   176     state: Optional[str] = Field(None, example='CA')
   177     zip: Optional[str] = Field(None, example='94301')
   178
   179
   180 class Category(BaseModel):
   181     id: Optional[int] = Field(None, example=1)
   182     name: Optional[str] = Field(None, example='Dogs')
   183
   184
   185 class User(BaseModel):
   186     id: Optional[int] = Field(None, example=10)
   187     username: Optional[str] = Field(None, example='theUser')
   188     firstName: Optional[str] = Field(None, example='John')
   189     lastName: Optional[str] = Field(None, example='James')
   190     email: Optional[str] = Field(None, example='john@email.com')
   191     password: Optional[str] = Field(None, example='12345')
   192     phone: Optional[str] = Field(None, example='12345')
   193     userStatus: Optional[int] = Field(None, description='User Status', example=1)
   194
   195
   196 class Tag(BaseModel):
   197     id: Optional[int] = None
   198     name: Optional[str] = None
   199
   200
   201 class Status1(Enum):
   202     available = 'available'
   203     pending = 'pending'
   204     sold = 'sold'
   205
   206
   207 class Pet(BaseModel):
   208     id: Optional[int] = Field(None, example=10)
   209     name: str = Field(..., example='doggie')
   210     category: Optional[Category] = None
   211     photoUrls: List[str]
   212     tags: Optional[List[Tag]] = None
   213     status: Optional[Status1] = Field(None, description='pet status in the store')
   214
   215
   216 class ApiResponse(BaseModel):
   217     code: Optional[int] = None
   218     type: Optional[str] = None
   219     message: Optional[str] = None
   220
   221
   222 class Customer(BaseModel):
   223     id: Optional[int] = Field(None, example=100000)
   224     username: Optional[str] = Field(None, example='fehguy')
   225     address: Optional[List[Address]] = None
 
 
 
★output/router/pet.py
     1 # generated by fastapi-codegen:
     2 #   filename:  openapi.yaml
     3 #   timestamp: 2024-01-02T04:42:03+00:00
     4
     5 from __future__ import annotations
     6
     7 from fastapi import APIRouter
     8
     9 from ..dependencies import *
    10
    11 router = APIRouter(tags=['pet'])
    12
    13
    14 @router.put('/pet', response_model=Pet, tags=['pet'])
    15 def update_pet(body: Pet) -> Pet:
    16     """
    17     Update an existing pet
    18     """
    19     pass
    20
    21
    22 @router.post('/pet', response_model=Pet, tags=['pet'])
    23 def add_pet(body: Pet) -> Pet:
    24     """
    25     Add a new pet to the store
    26     """
    27     pass
    28
    29
    30 @router.get('/pet/findByStatus', response_model=List[Pet], tags=['pet'])
    31 def find_pets_by_status(status: Optional[Status3] = 'available') -> List[Pet]:
    32     """
    33     Finds Pets by status
    34     """
    35     pass
    36
    37
    38 @router.get('/pet/findByTags', response_model=List[Pet], tags=['pet'])
    39 def find_pets_by_tags(tags: Optional[List[str]] = None) -> List[Pet]:
    40     """
    41     Finds Pets by tags
    42     """
    43     pass
    44
    45
    46 @router.get('/pet/{pet_id}', response_model=Pet, tags=['pet'])
    47 def get_pet_by_id(pet_id: int = Path(..., alias='petId')) -> Pet:
    48     """
    49     Find pet by ID
    50     """
    51     pass
    52
    53
    54 @router.post('/pet/{pet_id}', response_model=None, tags=['pet'])
    55 def update_pet_with_form(
    56     pet_id: int = Path(..., alias='petId'),
    57     name: Optional[str] = None,
    58     status: Optional[str] = None,
    59 ) -> None:
    60     """
    61     Updates a pet in the store with form data
    62     """
    63     pass
    64
    65
    66 @router.delete('/pet/{pet_id}', response_model=None, tags=['pet'])
    67 def delete_pet(
    68     api_key: Optional[str] = None, pet_id: int = Path(..., alias='petId')
    69 ) -> None:
    70     """
    71     Deletes a pet
    72     """
    73     pass
    74
    75
    76 @router.post('/pet/{pet_id}/uploadImage', response_model=ApiResponse, tags=['pet'])
    77 def upload_file(
    78     pet_id: int = Path(..., alias='petId'),
    79     additional_metadata: Optional[str] = Query(None, alias='additionalMetadata'),
    80     request: Request = ...,
    81 ) -> ApiResponse:
    82     """
    83     uploads an image
    84     """
    85     pass
 
 
 
★output/router/store.py
    86 # generated by fastapi-codegen:
    87 #   filename:  openapi.yaml
    88 #   timestamp: 2024-01-02T04:42:03+00:00
    89
    90 from __future__ import annotations
    91
    92 from fastapi import APIRouter
    93
    94 from ..dependencies import *
    95
    96 router = APIRouter(tags=['store'])
    97
    98
    99 @router.get(
   100     '/store/inventory', response_model=StoreInventoryGetResponse, tags=['store']
   101 )
   102 def get_inventory() -> StoreInventoryGetResponse:
   103     """
   104     Returns pet inventories by status
   105     """
   106     pass
   107
   108
   109 @router.post('/store/order', response_model=Order, tags=['store'])
   110 def place_order(body: Order = None) -> Order:
   111     """
   112     Place an order for a pet
   113     """
   114     pass
   115
   116
   117 @router.get('/store/order/{order_id}', response_model=Order, tags=['store'])
   118 def get_order_by_id(order_id: int = Path(..., alias='orderId')) -> Order:
   119     """
   120     Find purchase order by ID
   121     """
   122     pass
   123
   124
   125 @router.delete('/store/order/{order_id}', response_model=None, tags=['store'])
   126 def delete_order(order_id: int = Path(..., alias='orderId')) -> None:
   127     """
   128     Delete purchase order by ID
   129     """
   130     pass
 
 
 
★output/router/user.py
   131 # generated by fastapi-codegen:
   132 #   filename:  openapi.yaml
   133 #   timestamp: 2024-01-02T04:42:03+00:00
   134
   135 from __future__ import annotations
   136
   137 from fastapi import APIRouter
   138
   139 from ..dependencies import *
   140
   141 router = APIRouter(tags=['user'])
   142
   143
   144 @router.post(
   145     '/user', response_model=None, responses={'default': {'model': User}}, tags=['user']
   146 )
   147 def create_user(body: User = None) -> Union[None, User]:
   148     """
   149     Create user
   150     """
   151     pass
   152
   153
   154 @router.post('/user/createWithList', response_model=User, tags=['user'])
   155 def create_users_with_list_input(body: List[User] = None) -> User:
   156     """
   157     Creates list of users with given input array
   158     """
   159     pass
   160
   161
   162 @router.get('/user/login', response_model=str, tags=['user'])
   163 def login_user(username: Optional[str] = None, password: Optional[str] = None) -> str:
   164     """
   165     Logs user into the system
   166     """
   167     pass
   168
   169
   170 @router.get('/user/logout', response_model=None, tags=['user'])
   171 def logout_user() -> None:
   172     """
   173     Logs out current logged in user session
   174     """
   175     pass
   176
   177
   178 @router.get('/user/{username}', response_model=User, tags=['user'])
   179 def get_user_by_name(username: str) -> User:
   180     """
   181     Get user by user name
   182     """
   183     pass
   184
   185
   186 @router.put('/user/{username}', response_model=None, tags=['user'])
   187 def update_user(username: str, body: User = None) -> None:
   188     """
   189     Update user
   190     """
   191     pass
   192
   193
   194 @router.delete('/user/{username}', response_model=None, tags=['user'])
   195 def delete_user(username: str) -> None:
   196     """
   197     Delete user
   198     """
   199     pass