diff --git a/README.md b/README.md index fa63192..26b1e28 100644 --- a/README.md +++ b/README.md @@ -143,9 +143,35 @@ message Point { ### Per message annotation - | annotation | description | |------------|:---------------------------------------------------------------------------------------------------------| | @RootNode | If there are multiple types without an parent you can give a hint to the root node with this annotation. | +### Head annotation + +| annotation | description | +|------------|:----------------------------------------------------------| +| @Option | In head of your file you can place options for the parser | + + +### Head annotation "Option" + +The `@Option` have to follow by space separated options key and another space separated value + +``` +// @Option primitiveTypesWithLimits false + +message Point { + +} +``` + +Possible options are: + + +| option | description | def | +|--------------------------|:-----------------------------------------------------------------------------------------------------------|:-----| +| primitiveTypesWithLimits | If you dont like to get default Min and Max limits for primitive types, you can set this option to `false` | true | + + diff --git a/src/primitive-types.ts b/src/primitive-types.ts index f7ad639..890eabe 100644 --- a/src/primitive-types.ts +++ b/src/primitive-types.ts @@ -11,7 +11,7 @@ export class PrimitiveTypes { private static readonly MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; private static readonly MIN_SAFE_INTEGER = -this.MAX_SAFE_INTEGER; - public static readonly PRIMITIVE_TYPES: AsyncApiTypeMap = { + public static readonly PRIMITIVE_TYPES_WITH_LIMITS: AsyncApiTypeMap = { bytes: { type: 'string', 'x-primitive': 'bytes', @@ -85,4 +85,67 @@ export class PrimitiveTypes { 'x-primitive': 'double', }, }; + + public static readonly PRIMITIVE_TYPES_MINIMAL: AsyncApiTypeMap = { + bytes: { + type: 'string', + 'x-primitive': 'bytes', + }, + string: { + type: 'string', + 'x-primitive': 'string', + }, + bool: { + type: 'boolean', + 'x-primitive': 'bool', + }, + int32: { + type: 'integer', + 'x-primitive': 'int32', + }, + sint32: { + type: 'integer', + 'x-primitive': 'sint32', + }, + uint32: { + type: 'integer', + 'x-primitive': 'uint32', + }, + int64: { + type: 'integer', + 'x-primitive': 'int64', + }, + sint64: { + type: 'integer', + 'x-primitive': 'sint64', + }, + uint64: { + type: 'integer', + 'x-primitive': 'uint64', + }, + fixed32: { + type: 'number', + 'x-primitive': 'fixed32', + }, + fixed64: { + type: 'number', + 'x-primitive': 'fixed64', + }, + sfixed32: { + type: 'number', + 'x-primitive': 'sfixed32', + }, + sfixed64: { + type: 'number', + 'x-primitive': 'sfixed64', + }, + float: { + type: 'number', + 'x-primitive': 'float', + }, + double: { + type: 'number', + 'x-primitive': 'double', + }, + }; } diff --git a/src/protoj2jsonSchema.ts b/src/protoj2jsonSchema.ts index 3cfc327..9146450 100644 --- a/src/protoj2jsonSchema.ts +++ b/src/protoj2jsonSchema.ts @@ -8,6 +8,7 @@ import {AsyncAPISchemaDefinition} from '@asyncapi/parser/esm/spec-types/v3'; const ROOT_FILENAME = 'root'; const COMMENT_ROOT_NODE = '@RootNode'; +const COMMENT_OPTION = '@Option'; const COMMENT_EXAMPLE = '@Example'; const COMMENT_DEFAULT = '@Default'; @@ -17,11 +18,39 @@ class Proto2JsonSchema { keepCase: true, alternateCommentMode: true }; + private mapperOptions: { [key: string]: string | boolean } = { + primitiveTypesWithLimits: true + }; constructor(rawSchema: string) { + this.parseOptionsAnnotation(rawSchema); + this.process(ROOT_FILENAME, rawSchema); } + private parseOptionsAnnotation(rawSchema: string) { + const regex = /\s*(\/\/|\*)\s*@Option\s+(?\w+)\s+(?[^\r\n]+)/g; + let m: RegExpExecArray | null; + while ((m = regex.exec(rawSchema)) !== null) { + // This is necessary to avoid infinite loops with zero-width matches + if (m.index === regex.lastIndex) { + regex.lastIndex++; + } + + if (m.groups === undefined) { + break; + } + + if (m.groups.value === 'true') { + this.mapperOptions[m.groups.key] = true; + } else if (m.groups.value === 'false') { + this.mapperOptions[m.groups.key] = false; + } else { + this.mapperOptions[m.groups.key] = m.groups.value; + } + } + } + private process(filename: string, source: string | ProtoAsJson) { if (!isString(source)) { const srcObject = source as ProtoAsJson; @@ -173,7 +202,7 @@ class Proto2JsonSchema { */ // eslint-disable-next-line sonarjs/cognitive-complexity private compileMessage(item: protobuf.Type, stack: string[]): AsyncAPISchemaDefinition { - const properties: {[key: string]: AsyncAPISchemaDefinition} = {}; + const properties: { [key: string]: AsyncAPISchemaDefinition } = {}; const obj: v3.AsyncAPISchemaDefinition = { title: item.name, @@ -219,7 +248,7 @@ class Proto2JsonSchema { } if (field.comment) { - const minItemsPattern = /@maxItems\\s(\\d+?)/i; + const minItemsPattern = /@minItems\\s(\\d+?)/i; const maxItemsPattern = /@maxItems\\s(\\d+?)/i; let m: RegExpExecArray | null; if ((m = minItemsPattern.exec(field.comment)) !== null) { @@ -285,8 +314,10 @@ class Proto2JsonSchema { private compileField(field: protobuf.Field, parentItem: protobuf.Type, stack: string[]): v3.AsyncAPISchemaDefinition { let obj: v3.AsyncAPISchemaDefinition = {}; - if (PrimitiveTypes.PRIMITIVE_TYPES[field.type.toLowerCase()]) { - obj = Object.assign(obj, PrimitiveTypes.PRIMITIVE_TYPES[field.type.toLowerCase()]); + if (PrimitiveTypes.PRIMITIVE_TYPES_WITH_LIMITS[field.type.toLowerCase()]) { + obj = (this.mapperOptions.primitiveTypesWithLimits) ? + Object.assign(obj, PrimitiveTypes.PRIMITIVE_TYPES_WITH_LIMITS[field.type.toLowerCase()]) : + Object.assign(obj, PrimitiveTypes.PRIMITIVE_TYPES_MINIMAL[field.type.toLowerCase()]); obj['x-primitive'] = field.type; } else { const item = parentItem.lookupTypeOrEnum(field.type); @@ -330,6 +361,7 @@ class Proto2JsonSchema { comment = comment .replace(new RegExp(`\\s{0,15}${COMMENT_EXAMPLE}\\s{0,15}(.+)`, 'ig'), '') .replace(new RegExp(`\\s{0,15}${COMMENT_DEFAULT}\\s{0,15}(.+)`, 'ig'), '') + .replace(new RegExp(`\\s{0,15}${COMMENT_OPTION}\\s{0,15}(.+)`, 'ig'), '') .replace(new RegExp(`\\s{0,15}${COMMENT_ROOT_NODE}`, 'ig'), '') .replace(new RegExp('\\s{0,15}@(Min|Max|Pattern|Minimum|Maximum|ExclusiveMinimum|ExclusiveMaximum|MultipleOf|MaxLength|MinLength|MaxItems|MinItems)\\s{0,15}[\\d.]{1,20}', 'ig'), '') .trim(); @@ -341,12 +373,12 @@ class Proto2JsonSchema { return comment; } - private extractExamples(comment: string | null): (string|ProtoAsJson)[] | null { + private extractExamples(comment: string | null): (string | ProtoAsJson)[] | null { if (!comment) { return null; } - const examples: (string|ProtoAsJson)[] = []; + const examples: (string | ProtoAsJson)[] = []; let m: RegExpExecArray | null; const examplePattern = new RegExp(`\\s*${COMMENT_EXAMPLE}\\s(.+)$`, 'i'); @@ -404,6 +436,7 @@ class Proto2JsonSchema { } } } + /* eslint-enable security/detect-unsafe-regex */ private addDefaultFromCommentAnnotations(obj: AsyncAPISchemaDefinition, comment: string | null) { @@ -433,7 +466,7 @@ function tryParseToObject(value: string): string | ProtoAsJson { try { const json = JSON.parse(value); if (json) { - return json; + return json; } } catch (_) { // Ignored error, seams not to be a valid json. Maybe just an example starting with an "{" but is not a json. diff --git a/test/documents/realworld.train_run.proto.result.json b/test/documents/realworld.train_run.proto.result.json index d052433..1c92608 100644 --- a/test/documents/realworld.train_run.proto.result.json +++ b/test/documents/realworld.train_run.proto.result.json @@ -19,8 +19,6 @@ "properties": { "id": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId" }, @@ -34,23 +32,23 @@ "properties": { "year": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 9999, - "x-primitive": "int32", "description": "Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year" }, "month": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 12, - "x-primitive": "int32", "description": "Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day." }, "day": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 31, - "x-primitive": "int32", "description": "Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant." } } @@ -78,14 +76,10 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } } @@ -96,14 +90,10 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } } @@ -116,14 +106,10 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -148,8 +134,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -161,8 +145,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -170,8 +152,6 @@ }, "reihenfolge": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" }, "umsystem": { @@ -184,8 +164,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -215,8 +193,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -234,62 +210,70 @@ "properties": { "id": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId" }, + "nodeId": { + "type": "integer", + "x-primitive": "int32", + "minimum": 0, + "maximum": 1200, + "description": "Reference to a topology node.", + "examples": [ + "42217" + ] + }, "scheduled_time": { "title": "DateTime", "type": "object", "properties": { "year": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 9999, - "x-primitive": "int32", "description": "Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year" }, "month": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 12, - "x-primitive": "int32", "description": "Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day." }, "day": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 31, - "x-primitive": "int32", "description": "Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant." }, "hours": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 23, - "x-primitive": "int32", "description": "Hours of day in 24 hour format." }, "minutes": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 59, - "x-primitive": "int32", "description": "Minutes of hour of day." }, "seconds": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 60, - "x-primitive": "int32", "description": "Seconds of minutes of the time. Must normally be from 0 to 59. An API may allow the value 60 if it allows leap-seconds." }, "nanos": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 999999999, - "x-primitive": "int32", "description": "Fractions of seconds in nanoseconds." }, "timeOffset": { @@ -300,20 +284,16 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, { "title": "TimeZone", @@ -323,16 +303,16 @@ "type": "string", "x-primitive": "string", "description": "IANA Time Zone Database time zone.", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "version": { "type": "string", "x-primitive": "string", "description": "IANA Time Zone Database version number.", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } ] } @@ -344,51 +324,51 @@ "properties": { "year": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 9999, - "x-primitive": "int32", "description": "Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year" }, "month": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 12, - "x-primitive": "int32", "description": "Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day." }, "day": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 31, - "x-primitive": "int32", "description": "Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant." }, "hours": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 23, - "x-primitive": "int32", "description": "Hours of day in 24 hour format." }, "minutes": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 59, - "x-primitive": "int32", "description": "Minutes of hour of day." }, "seconds": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 60, - "x-primitive": "int32", "description": "Seconds of minutes of the time. Must normally be from 0 to 59. An API may allow the value 60 if it allows leap-seconds." }, "nanos": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 999999999, - "x-primitive": "int32", "description": "Fractions of seconds in nanoseconds." }, "timeOffset": { @@ -399,20 +379,16 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, { "title": "TimeZone", @@ -422,16 +398,16 @@ "type": "string", "x-primitive": "string", "description": "IANA Time Zone Database time zone.", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "version": { "type": "string", "x-primitive": "string", "description": "IANA Time Zone Database version number.", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } ] } @@ -443,15 +419,11 @@ "properties": { "event_id_from": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId" }, "event_id_to": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId" }, @@ -461,8 +433,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -498,8 +468,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -535,14 +503,12 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "event_id_to": { "title": "UInt32Value", @@ -550,14 +516,12 @@ "properties": { "value": { "type": "integer", - "minimum": 0, - "maximum": 4294967295, "x-primitive": "uint32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "event_link_properties_id": { "title": "UInt64Value", @@ -565,33 +529,29 @@ "properties": { "value": { "type": "integer", - "minimum": 0, - "maximum": 9007199254740991, "x-primitive": "uint64", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "min_duration": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "purposes": { "type": "array", "items": { "type": "string", "x-primitive": "string", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, { "title": "MovementMsg", @@ -599,19 +559,15 @@ "properties": { "event_id_from": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "event_id_to": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "event_link_properties_id": { "title": "Int32Value", @@ -619,31 +575,27 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "min_duration": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "is_min_duration_calculated": { "type": "boolean", "x-primitive": "bool", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "is_stop_over": { "type": "boolean", "x-primitive": "bool", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "fahrstrategie": { "title": "FahrstrategieEnum", @@ -662,10 +614,10 @@ "FS_NORMAL": 3, "FS_FAHRZEIT_VERTEILEN": 4 }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } ] } @@ -682,8 +634,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -695,8 +645,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -704,8 +652,6 @@ }, "reihenfolge": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" }, "umsystem": { @@ -718,8 +664,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -749,8 +693,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -778,8 +720,6 @@ "properties": { "id": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId" }, @@ -793,23 +733,23 @@ "properties": { "year": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 9999, - "x-primitive": "int32", "description": "Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year" }, "month": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 12, - "x-primitive": "int32", "description": "Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day." }, "day": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 31, - "x-primitive": "int32", "description": "Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant." } } @@ -837,14 +777,10 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } } @@ -855,14 +791,10 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } } @@ -875,14 +807,10 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -907,8 +835,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -920,8 +846,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -929,8 +853,6 @@ }, "reihenfolge": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" }, "umsystem": { @@ -943,8 +865,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -974,8 +894,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -993,62 +911,70 @@ "properties": { "id": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId" }, + "nodeId": { + "type": "integer", + "x-primitive": "int32", + "minimum": 0, + "maximum": 1200, + "description": "Reference to a topology node.", + "examples": [ + "42217" + ] + }, "scheduled_time": { "title": "DateTime", "type": "object", "properties": { "year": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 9999, - "x-primitive": "int32", "description": "Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year" }, "month": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 12, - "x-primitive": "int32", "description": "Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day." }, "day": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 31, - "x-primitive": "int32", "description": "Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant." }, "hours": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 23, - "x-primitive": "int32", "description": "Hours of day in 24 hour format." }, "minutes": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 59, - "x-primitive": "int32", "description": "Minutes of hour of day." }, "seconds": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 60, - "x-primitive": "int32", "description": "Seconds of minutes of the time. Must normally be from 0 to 59. An API may allow the value 60 if it allows leap-seconds." }, "nanos": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 999999999, - "x-primitive": "int32", "description": "Fractions of seconds in nanoseconds." }, "timeOffset": { @@ -1059,20 +985,16 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, { "title": "TimeZone", @@ -1082,16 +1004,16 @@ "type": "string", "x-primitive": "string", "description": "IANA Time Zone Database time zone.", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "version": { "type": "string", "x-primitive": "string", "description": "IANA Time Zone Database version number.", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } ] } @@ -1103,51 +1025,51 @@ "properties": { "year": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 9999, - "x-primitive": "int32", "description": "Year of the date. Must be from 1 to 9999, or 0 to specify a date without a year" }, "month": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 12, - "x-primitive": "int32", "description": "Month of a year. Must be from 1 to 12, or 0 to specify a year without a month and day." }, "day": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 31, - "x-primitive": "int32", "description": "Day of a month. Must be from 1 to 31 and valid for the year and month, or 0 to specify a year by itself or a year and month where the day isn't significant." }, "hours": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 23, - "x-primitive": "int32", "description": "Hours of day in 24 hour format." }, "minutes": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 59, - "x-primitive": "int32", "description": "Minutes of hour of day." }, "seconds": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 60, - "x-primitive": "int32", "description": "Seconds of minutes of the time. Must normally be from 0 to 59. An API may allow the value 60 if it allows leap-seconds." }, "nanos": { "type": "integer", + "x-primitive": "int32", "minimum": 0, "maximum": 999999999, - "x-primitive": "int32", "description": "Fractions of seconds in nanoseconds." }, "timeOffset": { @@ -1158,20 +1080,16 @@ "properties": { "seconds": { "type": "integer", - "minimum": -9007199254740991, - "maximum": 9007199254740991, "x-primitive": "int64", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "nanos": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, { "title": "TimeZone", @@ -1181,16 +1099,16 @@ "type": "string", "x-primitive": "string", "description": "IANA Time Zone Database time zone.", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "version": { "type": "string", "x-primitive": "string", "description": "IANA Time Zone Database version number.", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } ] } @@ -1202,15 +1120,11 @@ "properties": { "event_id_from": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId" }, "event_id_to": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId" }, @@ -1220,8 +1134,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -1257,8 +1169,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -1294,14 +1204,12 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "event_id_to": { "title": "UInt32Value", @@ -1309,14 +1217,12 @@ "properties": { "value": { "type": "integer", - "minimum": 0, - "maximum": 4294967295, "x-primitive": "uint32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "event_link_properties_id": { "title": "UInt64Value", @@ -1324,33 +1230,29 @@ "properties": { "value": { "type": "integer", - "minimum": 0, - "maximum": 9007199254740991, "x-primitive": "uint64", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "min_duration": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "purposes": { "type": "array", "items": { "type": "string", "x-primitive": "string", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, { "title": "MovementMsg", @@ -1358,19 +1260,15 @@ "properties": { "event_id_from": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "event_id_to": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "event_link_properties_id": { "title": "Int32Value", @@ -1378,31 +1276,27 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, "description": "ObjectId", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "min_duration": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "is_min_duration_calculated": { "type": "boolean", "x-primitive": "bool", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "is_stop_over": { "type": "boolean", "x-primitive": "bool", - "x-parser-schema-id": "" + "x-parser-schema-id": "" }, "fahrstrategie": { "title": "FahrstrategieEnum", @@ -1421,10 +1315,10 @@ "FS_NORMAL": 3, "FS_FAHRZEIT_VERTEILEN": 4 }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } }, - "x-parser-schema-id": "" + "x-parser-schema-id": "" } ] } @@ -1441,8 +1335,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -1454,8 +1346,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -1463,8 +1353,6 @@ }, "reihenfolge": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" }, "umsystem": { @@ -1477,8 +1365,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, @@ -1508,8 +1394,6 @@ "properties": { "value": { "type": "integer", - "minimum": -2147483648, - "maximum": 2147483647, "x-primitive": "int32" } }, diff --git a/test/documents/realworld.train_run.yaml b/test/documents/realworld.train_run.yaml index 204a930..8d1536b 100644 --- a/test/documents/realworld.train_run.yaml +++ b/test/documents/realworld.train_run.yaml @@ -14,6 +14,8 @@ components: schemaFormat: 'application/vnd.google.protobuf;version=3' payload: | syntax = "proto3"; + + // @Option primitiveTypesWithLimits false import "google/protobuf/timestamp.proto"; import "google/protobuf/wrappers.proto"; @@ -63,6 +65,12 @@ components: message TimetableEventMsg { //ObjectId int32 id = 1; + + // Reference to a topology node. + // @Example 42217 + // @Min 0 + // @Max 1200 + int32 nodeId = 17; google.type.DateTime scheduled_time = 3; google.type.DateTime production_time = 4;