asyncee / swagger_codegen

Generate API clients by parsing Swagger definitions
45 stars 17 forks source link

generating classes for no direct endpoint #12

Closed martin0 closed 4 years ago

martin0 commented 4 years ago

Hi, I have a openapi v3 file for which i'm wanting to generate python client classes

I have two broad issues with the generated code at present.

where a schema is used as the root of an endpoints request or response, things seem ok but if a schema only plays a part a higher level schema, then the class name generated is None

eg below, contract corresponds to an endpoint, but rules only exists within contract, it has no endpoint of its own.

"schemas": { "authStatus": { "type": "object", "properties": { "authenticated": { "description": "Brokerage session is authenticated", "type": "boolean" }, "connected": { "description": "Connected to backend", "type": "boolean" }, "competing": { "description": "Brokerage session is competing, e.g. user is logged in to IBKR Mobile, WebTrader, TWS or other trading platforms.", "type": "boolean" }, "fail": { "description": "Authentication failed, why.", "type": "string" }, "message": { "description": "System messages that may affect trading", "type": "string" }, "prompts": { "type": "array", "description": "Prompt messages that may affect trading or the account", "items": { "type": "string" } } } }, "contract": { "description": "Contains all details of the contract, including rules you can use when placing orders", "type": "object", "properties": { "r_t_h": { "type": "boolean", "description": "true means you can trade outside RTH(regular trading hours)" }, "con_id": { "type": "string", "description": "same as that in request" }, "company_name": { "type": "string" }, "exchange": { "type": "string" }, "local_symbol": { "type": "string", "description": "for exmple FB" }, "instrument_type": { "type": "string", "description": "for example STK" }, "currency": { "type": "string" }, "companyName": { "type": "string" }, "category": { "type": "string" }, "industry": { "type": "string" }, "rules": { "type": "object", "properties": { "orderTypes": { "type": "array", "items": { ........

asyncee commented 4 years ago

Can you create minimal example that demonstrates the problem?

martin0 commented 4 years ago

This illustrates the problem `{ "openapi": "3.0.0", "info": { "title": "Client Portal Web API", "description": "Production version of the Client Portal Web API", "version": "1.0.0" }, "paths": { "/iserver/contract/{conid}/info": { "get": { "summary": "Contract Info", "description": "get contract details, you can use this to prefill your order before you submit an order", "tags": [ "Contract" ], "parameters": [ { "name": "conid", "in": "path", "required": true, "description": "contract id", "schema": { "type": "string" } } ], "responses": { "200": { "description": "returns an object", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/contract" } } } } } } }

},
"servers": [
    {
        "url": "https://localhost:5000/v1/portal"
    }
],
"components": {
    "requestBodies": {
        "Body": {
            "content": {
                "application/json": {
                    "schema": {
                        "type": "object",
                        "properties": {
                            "acctIds": {
                                "type": "array",
                                "items": {
                                    "type": "string",
                                    "description": "account id"
                                }
                            }
                        }
                    }
                }
            },
            "description": "an array of account ids",
            "required": true
        }
    },
    "schemas": {
        "contract": {
            "description": "Contains all details of the contract, including rules you can use when placing orders",
            "type": "object",
            "properties": {
                "con_id": {
                    "type": "string",
                    "description": "same as that in request"
                },
                "company_name": {
                    "type": "string"
                },
                "exchange": {
                    "type": "string"
                },
                "local_symbol": {
                    "type": "string",
                    "description": "for exmple FB"
                },

                "rules": {
                    "type": "object",
                    "properties": {
                        "orderTypes": {
                            "type": "array",
                            "items": {
                                "type": "string",
                                "description": "store available order types for this contract"
                            }
                        },
                        "orderTypesOutside": {
                            "type": "array",
                            "items": {
                                "type": "string",
                                "description": "store available order types for this contract outside regular hours"
                            }
                        }
                    }
                }
            }
        }
    }
}

}`

asyncee commented 4 years ago

Thank you, i have just fixed it and released version 0.1.25. Please upgrade and try again.

martin0 commented 4 years ago

Awesome - thanks asyncee - i'll get to it tomorrow, and let you know

martin0 commented 4 years ago

looks good, but there's another scenario with "object" I'll post a separate issue