-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[TS][Fetch] Add support for openapi maps/dictionaries to be generated as typescript map #2913
[TS][Fetch] Add support for openapi maps/dictionaries to be generated as typescript map #2913
Conversation
Change isContainer -> isListContainer for existing array support. Add isMapContainer control flow, adding map support. Add utility function to help map openapi map/dictionaries to ts maps. Close OpenAPITools#1878
can you provide an minimal example .yml file and the corresponding output? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@macjohnny Given an example 2.0 spec in json as the first code block here, this PR allows generation of code files like the bottom block. {
"swagger": "2.0",
"info": { "version": "1.0", "title": "map-spec 1.0" },
"paths":{},
"definitions": {
"Measurements": {
"type": "object",
"properties": {
"meteringPointId": { "type": "string" },
"year": { "$ref": "#/definitions/AggregatedMeasurements" },
"month": { "type": "object", "additionalProperties": { "$ref": "#/definitions/AggregatedMeasurements" } },
"day": { "type": "object", "additionalProperties": { "$ref": "#/definitions/AggregatedMeasurements" } },
"hour": { "type": "object", "additionalProperties": { "$ref": "#/definitions/AggregatedMeasurements" } }
}
},
"AggregatedMeasurements": {
"type": "object",
"properties": {
"min": { "format": "double", "type": "number" },
"max": { "format": "double", "type": "number" },
"avg": { "format": "double", "type": "number" },
"values": { "type": "object", "additionalProperties": { "$ref": "#/definitions/Volume" } }
}
},
"Volume": {
"type": "object",
"properties": {
"value": { "format": "double", "type": "number" },
"status": { "enum": ["OK", "Est"], "type": "string" },
"resolution": { "enum": ["Quarter", "Hour", "Month"], "type": "string" }
}
}
}
}
// tslint:disable
/**
* map-spec 1.0
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import { exists, mapValues } from '../runtime';
import {
AggregatedMeasurements,
AggregatedMeasurementsFromJSON,
AggregatedMeasurementsToJSON,
} from './';
/**
*
* @export
* @interface Measurements
*/
export interface Measurements {
/**
*
* @type {string}
* @memberof Measurements
*/
meteringPointId?: string;
/**
*
* @type {AggregatedMeasurements}
* @memberof Measurements
*/
year?: AggregatedMeasurements;
/**
*
* @type {{ [key: string]: AggregatedMeasurements; }}
* @memberof Measurements
*/
month?: { [key: string]: AggregatedMeasurements; };
/**
*
* @type {{ [key: string]: AggregatedMeasurements; }}
* @memberof Measurements
*/
day?: { [key: string]: AggregatedMeasurements; };
/**
*
* @type {{ [key: string]: AggregatedMeasurements; }}
* @memberof Measurements
*/
hour?: { [key: string]: AggregatedMeasurements; };
}
export function MeasurementsFromJSON(json: any): Measurements {
return {
'meteringPointId': !exists(json, 'meteringPointId') ? undefined : json['meteringPointId'],
'year': !exists(json, 'year') ? undefined : AggregatedMeasurementsFromJSON(json['year']),
'month': !exists(json, 'month') ? undefined : mapValues(json['month'], AggregatedMeasurementsFromJSON),
'day': !exists(json, 'day') ? undefined : mapValues(json['day'], AggregatedMeasurementsFromJSON),
'hour': !exists(json, 'hour') ? undefined : mapValues(json['hour'], AggregatedMeasurementsFromJSON),
};
}
export function MeasurementsToJSON(value?: Measurements): any {
if (value === undefined) {
return undefined;
}
return {
'meteringPointId': value.meteringPointId,
'year': AggregatedMeasurementsToJSON(value.year),
'month': value.month === undefined ? undefined : mapValues(value.month, AggregatedMeasurementsToJSON),
'day': value.day === undefined ? undefined : mapValues(value.day, AggregatedMeasurementsToJSON),
'hour': value.hour === undefined ? undefined : mapValues(value.hour, AggregatedMeasurementsToJSON),
};
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Looks good to me.
@ehvattum thanks again for your contribution, which has been included in the v4.0.1 release (https://twitter.com/oas_generator/status/1135534738658062336) |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master
,4.1.x
,5.0.x
. Default:master
.cc. @TiFu @taxpon @sebastianhaas @kenisteward @Vrolijkx @macjohnny @nicokoenig @topce
Description of the PR
.mustache
files only.