|
| 1 | +# OSEG - OpenAPI SDK Example Generator |
| 2 | + |
| 3 | +Create (almost) ready to use SDK snippets for SDKs generated using [openapi-generator](https://openapi-generator.tech/) using example data from your OpenAPI spec. |
| 4 | + |
| 5 | +## Where does the example data come from? |
| 6 | + |
| 7 | +Example data used to generate the code snippets can come from a number of places: |
| 8 | + |
| 9 | +* example or examples values in schema |
| 10 | +* default values in schema |
| 11 | +* Externally referenced JSON files defined in schema |
| 12 | +* You can also create a JSON file with examples for all the endpoints you want |
| 13 | + |
| 14 | +OSEG currently generates one code snippet file per `requestBody` definition, but only a single example per `parameters` definition. |
| 15 | + |
| 16 | +In other words, you can generate multiple examples of the same operation/endpoint by having multiple `requestBody` definitions. Each generate example will have different data embedded within it. However, since `parameters` is tied to a single operation, the same data will apply to any and all `requestBody` definitions. |
| 17 | + |
| 18 | +If you use a custom JSON file with examples you can define as many examples per endpoint as you want, since you can define each data source separately (`query`, `path`, `header`, `cookie`, and `body`) per endpoint. |
| 19 | + |
| 20 | +## How to run |
| 21 | + |
| 22 | +The entrypoint to this project is `run.py`. It currently supports two commands: |
| 23 | + |
| 24 | +### config-help |
| 25 | + |
| 26 | +Prints all config options available to a given generator. |
| 27 | + |
| 28 | +Run `python3 run.py config-help --help` for more details. |
| 29 | + |
| 30 | +Show config options for the `python` generator: |
| 31 | + |
| 32 | +```bash |
| 33 | +python3 run.py config-help -g python |
| 34 | +``` |
| 35 | + |
| 36 | +## Tests |
| 37 | + |
| 38 | +See [tests directory](tests). |
| 39 | + |
| 40 | +## Feature support |
| 41 | + |
| 42 | +The aim of this project is to cover the most common use-cases in an OpenAPI spec. |
| 43 | + |
| 44 | +### Supported |
| 45 | + |
| 46 | +* Requests with and without formdata: `openapi-generator` will create a different interface if an endpoint's `content-type` has formdata (`multipart/form-data` or `application/x-www-form-urlencoded`) and everything else |
| 47 | +* Discriminators with `allOf` |
| 48 | + |
| 49 | +### Issues |
| 50 | + |
| 51 | +The following are issues with the SDK code generated by `openapi-generator`. |
| 52 | + |
| 53 | +* `allOf` without a discriminator: Depending on the `openapi-generator` generator used, the generated SDK may be completely broken |
| 54 | + * `typescript-node` SDK code is generated broken by `openapi-generator` |
| 55 | + * Other SDKs currently supported by OSEG will usually just use a generic `object` type |
| 56 | +* `anyOf` |
| 57 | + * `typescript-node` generated SDK does not set data |
| 58 | + * `php` generated SDK does not set data |
| 59 | + * Other SDKs currently supported by OSEG generate a class |
| 60 | +* `oneOf` |
| 61 | + * `typescript-node` generated SDK does not set data |
| 62 | + * `php` generated SDK does not set data |
| 63 | + * Other SDKs currently supported by OSEG generate a class |
| 64 | +* Multiple values in `type` definition. New in OpenAPI 3.1 `type` can now be an array of supported types |
| 65 | + * `c#`, `java`, `ruby` Generate a class |
| 66 | + * `python` generates a class but does not use it, types property as the first value in `type` |
| 67 | + * `php` generates a class, data not set |
| 68 | + * `typescript-node` generates a class, data not set |
| 69 | +* `openapi-generator` generates a class for inline schema with `type=object`. If two or more Operations share identical inline schema definitions, `openapi-generator` will only generate a class for one of the Operations, and all Operations will reference this class. The name of the class depends on which Operation is read first by `openapi-generator`, but it may not reflect the first definition within the OAS file and thus is impossible for OSEG to know the name of the class ahead of time. |
0 commit comments