Skip to content

Commit

Permalink
fix(parser): interface properties were skipped during generation
Browse files Browse the repository at this point in the history
  • Loading branch information
vmasek committed Mar 7, 2018
1 parent 0a0de44 commit 3e694ad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,17 @@ function defineEnum(enumSchema: (string | boolean | number | {})[], definitionKe
};
}

function parseInterfaceProperties({properties}: Schema = {}): Property[] {
return Object.entries<Schema>(properties || {}).map(
function parseInterfaceProperties(properties: {[propertyName: string]: Schema} = {}): Property[] {
return Object.entries<Schema>(properties).map(
([propName, propSchema]: [string, Schema]) => {
const property: Property = {
name: propName,
isRef: '$ref' in propSchema || (propSchema.type === 'array' && propSchema.items && '$ref' in propSchema.items),
isArray: propSchema.type === 'array',
};

// console.log('prop', property.name);

if (Array.isArray(propSchema.items)) {
console.warn('Arrays with type diversity are currently not supported');
property.type = 'any';
Expand Down Expand Up @@ -98,8 +100,8 @@ function parseInterfaceProperties({properties}: Schema = {}): Property[] {
}

function defineInterface(schema: Schema, definitionKey: string): Definition {
const properties: Property[] = parseInterfaceProperties(schema.properties);
const name = typeName(definitionKey);
const properties: Property[] = parseInterfaceProperties(schema.properties);

return {
name: name,
Expand Down Expand Up @@ -145,7 +147,7 @@ function transformParameters(parameters: Parameter[]): Parameter[] {
return Array.isArray(parameters)
// todo: required params
? parameters.map((param) => {
console.log('==>', param);
// console.log('==>', param);

const typescriptType = toTypescriptType(
dereferenceType(param.$ref || ('schema' in param && param.schema.$ref)) || param.type,
Expand Down

0 comments on commit 3e694ad

Please sign in to comment.