| 24 | } |
| 25 | |
| 26 | private parseModel(name: string, models: OpenAPIV3.ComponentsObject): Oas.Body { |
| 27 | const { schemas } = models!; |
| 28 | const model = schemas![name] as OpenAPIV3.SchemaObject; |
| 29 | const body = {} as Oas.Body; |
| 30 | body.properties = []; |
| 31 | |
| 32 | if (model.properties === undefined) { |
| 33 | body.properties.push({ ...(model as Oas.BodyParam) }); |
| 34 | return body; |
| 35 | } |
| 36 | |
| 37 | const { properties, required, example } = model; |
| 38 | |
| 39 | Object.entries(properties).forEach(([key, property]) => { |
| 40 | let bodyParam = {} as Oas.BodyParam; |
| 41 | |
| 42 | if ('$ref' in property) { |
| 43 | const name = property.$ref.split('/').pop()!; |
| 44 | // TODO: Consider parsing inner examples if available |
| 45 | // Maybe just merge to the top example |
| 46 | const { properties: innerParams } = this.parseModel(name, models); |
| 47 | |
| 48 | bodyParam = { |
| 49 | ...innerParams[0], |
| 50 | }; |
| 51 | bodyParam.name = key; |
| 52 | } else { |
| 53 | const tempProperty = property as OpenAPIV3.SchemaObject; |
| 54 | bodyParam = { |
| 55 | name: key, |
| 56 | type: tempProperty.type!, |
| 57 | description: tempProperty.description ?? '', |
| 58 | required: required === undefined ? false : required.includes(key) ? true : false, |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | body.properties.push(bodyParam); |
| 63 | }); |
| 64 | |
| 65 | if (example !== undefined) { |
| 66 | body.examples = example as Map<string, any>; |
| 67 | } |
| 68 | return body; |
| 69 | } |
| 70 | |
| 71 | private parseRequestBody( |
| 72 | schema: Oas.PropertySchema, |