Skip to content

Commit

Permalink
fix: recursively transform schema with array 'type' field
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Mar 16, 2023
1 parent 9ded238 commit f93da21
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 44 deletions.
7 changes: 3 additions & 4 deletions src/functions/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ export const transformSchemaElement = (schema: any) => {
)}. Type doesn't support an array with multiple values. Use anyOf/oneOf.`,
);
}
return {

return transformSchemaElement({
...schema,
type: schema.type.filter((a: string) => a !== 'null')[0],
nullable: true,
};
});
} else {
// edge case where type is an array with only 1 element
if (schema.type.length === 1) {
Expand Down Expand Up @@ -177,8 +178,6 @@ export const getSchemaForEndpoint = (endpointName: string) => {
anyOfResult['anyOf'].push(item);
}

console.log('anyOfResult', endpointName, anyOfResult);

responses.response[200] = anyOfResult;
}

Expand Down
60 changes: 20 additions & 40 deletions test/tests/__snapshots__/get-schema-for-endpoint.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4359,10 +4359,8 @@ Testnet: https://github.com/input-output-hk/metadata-registry-testnet/
"description": "Number of decimal places of the asset unit",
"example": 6,
"maximum": 255,
"type": [
"integer",
"null",
],
"nullable": true,
"type": "integer",
},
"description": {
"description": "Asset description",
Expand All @@ -4372,10 +4370,8 @@ Testnet: https://github.com/input-output-hk/metadata-registry-testnet/
"logo": {
"description": "Base64 encoded logo of the asset",
"example": "iVBORw0KGgoAAAANSUhEUgAAADAAAAAoCAYAAAC4h3lxAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAAB3RJTUUH5QITCDUPjqwFHwAAB9xJREFUWMPVWXtsU9cZ/8499/r6dZ3E9rUdO7ZDEgglFWO8KaOsJW0pCLRKrN1AqqYVkqoqrYo0ja7bpElru1WairStFKY9WzaE1E1tx+jokKqwtqFNyhKahE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dJBFBKwVIlXJ2JxqKCxbwyHkvoCkAlv9/71U+7Oq+UJWDZ0hViJBL1cRynbNq0sSeeiPl6ei4NqIqq6TSmlB7X6bjuTEY5pgWfzwxGPZhMpt39/b3vzvWXFGCzulZjjM/DrauDwcAr8bjcgzGjZUuVBMH8k2uDX7wCAFDr8n2LEPI7SqmhTP6SzVbz6MDlz0/nDpT8EmOM22HOvUeWU2wp8iyLgRL6hk7Hrc2SBwC4MTlykmXZRozxn00mbVcphNA5jJmV+chr6oDd5l6jN/A/TqfSuwEAGITGMIsvGo3GTwTB3Dc2NjGSxdZYq4VIOOoNBANnKE0XPXE3brjHOTQ08k2MmVZOxzVJCbkFIQSCYEphzPaFQuGzTpfjb319PZ8UFXin/5OvrHPg/9HueAH/BSUqOuNZm4fyAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIxLTAyLTE5VDA4OjUyOjI1KzAwOjAwCmFGlgAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMS0wMi0xOVQwODo1MjoyMyswMDowMBjsyxAAAAAASUVORK5CYII=",
"type": [
"string",
"null",
],
"nullable": true,
"type": "string",
},
"name": {
"description": "Asset name",
Expand All @@ -4384,18 +4380,14 @@ Testnet: https://github.com/input-output-hk/metadata-registry-testnet/
},
"ticker": {
"example": "nutc",
"type": [
"string",
"null",
],
"nullable": true,
"type": "string",
},
"url": {
"description": "Asset website",
"example": "https://www.stakenuts.com/",
"type": [
"string",
"null",
],
"nullable": true,
"type": "string",
},
},
"required": [
Expand Down Expand Up @@ -19461,50 +19453,38 @@ relative to the start of the network
"description": {
"description": "Description of the stake pool",
"example": "The best pool ever",
"type": [
"string",
"null",
],
"nullable": true,
"type": "string",
},
"hash": {
"description": "Hash of the metadata file",
"example": "47c0c68cb57f4a5b4a87bad896fc274678e7aea98e200fa14a1cb40c0cab1d8c",
"type": [
"string",
"null",
],
"nullable": true,
"type": "string",
},
"homepage": {
"description": "Home page of the stake pool",
"example": "https://stakentus.com/",
"type": [
"string",
"null",
],
"nullable": true,
"type": "string",
},
"name": {
"description": "Name of the stake pool",
"example": "Stake Nuts",
"type": [
"string",
"null",
],
"nullable": true,
"type": "string",
},
"ticker": {
"description": "Ticker of the stake pool",
"example": "NUTS",
"type": [
"string",
"null",
],
"nullable": true,
"type": "string",
},
"url": {
"description": "URL to the stake pool metadata",
"example": "https://stakenuts.com/mainnet.json",
"type": [
"string",
"null",
],
"nullable": true,
"type": "string",
},
},
"required": [
Expand Down

0 comments on commit f93da21

Please sign in to comment.