cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert Go types to a valid Swagger spec?

Highlighted
New Member

How to convert Go types to a valid Swagger spec?

If a Go schema has a type defined as array[reference[name_of_schema]],
how does that translate to a valid Swagger spec?
Below I've pasted the original schema that includes type definitinos like this,
and below that I've pasted the (currently invalid) Swagger YAML that I made out of it.
I already know the for an array of strings, which would be "array[string]" in the original JSON representation that I am
working with, it would need to change to:

type: array
items:
  type: string
I just don't know what to do when it's an array of references. Othen IDs are defined as a reference to an object as well.
So here's an example of the original schema as JSON:


{
"baseType": "schema", "collectionFilters": { // some irrelevant stuff here }, "id": "adfsConfig", "links": { "self": "https://ec2-52-33-26-235.us-west-2.compute.amazonaws.com/v3/schemas/adfsConfig" }, "pluralName": "adfsConfigs", "resourceActions": { "disable": {}, "testAndEnable": { "input": "samlConfigTestInput", "output": "samlConfigTestOutput" } }, "resourceFields": { "accessMode": { "create": true, "options": [ "required", "restricted", "unrestricted" ], "required": true, "type": "enum", "update": true }, "allowedPrincipalIds": { "create": true, "nullable": true, "type": "array[reference[principal]]", "update": true }, "annotations": { "create": true, "nullable": true, "type": "map[string]", "update": true }, "created": { "create": false, "nullable": true, "type": "date", "update": false }, "creatorId": { "create": false, "type": "reference[/v3/schemas/user]", "update": false }, "displayNameField": { "create": true, "nullable": true, "required": true, "type": "string", "update": true }, "enabled": { "create": true, "default": false, "type": "boolean", "update": true }, "groupsField": { "create": true, "nullable": true, "required": true, "type": "string", "update": true }, "idpMetadataContent": { "create": true, "nullable": true, "required": true, "type": "string", "update": true }, "labels": { "create": true, "nullable": true, "type": "map[string]", "update": true }, "name": { "create": true, "nullable": true, "type": "dnsLabel", "update": false }, "ownerReferences": { "create": false, "nullable": true, "type": "array[ownerReference]", "update": false }, "rancherApiHost": { "create": true, "nullable": true, "required": true, "type": "string", "update": true }, "removed": { "create": false, "nullable": true, "type": "date", "update": false }, "spCert": { "create": true, "nullable": true, "required": true, "type": "string", "update": true }, "spKey": { "create": true, "nullable": true, "required": true, "type": "password", "update": true }, "type": { "create": true, "nullable": true, "type": "string", "update": false }, "uidField": { "create": true, "nullable": true, "required": true, "type": "string", "update": true }, "userNameField": { "create": true, "nullable": true, "required": true, "type": "string", "update": true }, "uuid": { "create": false, "nullable": true, "type": "string", "update": false } }, "resourceMethods": [ "PUT", "GET" ], "type": "schema", "version": { "group": "management.cattle.io", "path": "/v3", "version": "v3" }}
 
 
And then I took all of that and reduced it into this Swagger definition:
 
adfsConfig:
    properties:
        accessMode:
            options: [required, restricted, unrestricted]
            type: enum
        allowedPrincipalIds:
            type: 'array[reference[principal]]'
        annotations:
            type: 'map[string]'
        created:
            type: date
        creatorId:
            type: 'reference[/v3/schemas/user]'
        displayNameField:
            type: string
        enabled:
            default: false
            type: boolean
        groupsField:
            type: string
        idpMetadataContent:
            type: string
        labels:
            type: 'map[string]'
        name:
            type: dnsLabel
        ownerReferences:
            type: 'array[ownerReference]'
        rancherApiHost:
            type: string
        removed:
            type: date
        spCert:
            type: string
        spKey:
            type: password
        type:
            type: string
        uidField:
            type: string
        userNameField:
            type: string
        uuid:
            type: string
    required:
        - userNameField
        - idpMetadataContent
        - displayNameField
        - accessMode
        - uidField
        - rancherApiHost
        - spCert
        - groupsField
        - spKey
    type: object
 
 
Does anyone see how to make this a valid Swagger definition while preserving the meaning of the original?
 
 
 

 

New Here?
Join us and watch the welcome video:
Top Kudoed Authors