Skip to content

Instantly share code, notes, and snippets.

@zacharyc
Created November 19, 2021 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zacharyc/ce809dca011cd1edbc937b42bbb85829 to your computer and use it in GitHub Desktop.
Save zacharyc/ce809dca011cd1edbc937b42bbb85829 to your computer and use it in GitHub Desktop.
How do I do this better
const openApiList = [
{
swagger: "2.0",
info: {
description: "Test API",
version: "1.0.0",
title: "Request Catcher Testing API",
},
host: "kyung.requestcatcher.com",
basePath: "/root",
schemes: ["https"],
paths: {
"/test/{id}": {
post: {
summary: "Post Body Test",
description: "",
operationId: "testPost",
consumes: ["application/json"],
produces: ["application/json"],
parameters: [
{
name: "id",
in: "path",
required: true,
},
{
name: "body",
in: "body",
required: false,
type: "object",
},
],
},
get: {
operationId: "testGet",
produces: ["application/json"],
parameters: [
{
name: "id",
in: "path",
required: true,
},
],
},
},
},
},
]
// const foo = openApiList[0]
// const pathOptions = []
const pathOptStrings = Object.keys(openApiList[0].paths)
.map((pathKey) => {
return Object.keys((openApiList[0].paths as any)[pathKey]).map((methodKey) => {
return (openApiList[0].paths as any)[pathKey][methodKey].operationId
})
})
.flat()
console.log(pathOptStrings)
const pathOpts = pathOptStrings.map((s) => {
key: s,
value: s,
children: s
})
@airkitjeremy
Copy link

const openApiList = [
        {
            swagger: "2.0",
            info: {
                description: "Test API",
                version: "1.0.0",
                title: "Request Catcher Testing API",
            },
            host: "kyung.requestcatcher.com",
            basePath: "/root",
            schemes: ["https"],
            paths: {
                "/test/{id}": {
                    post: {
                        summary: "Post Body Test",
                        description: "",
                        operationId: "testPost",
                        consumes: ["application/json"],
                        produces: ["application/json"],
                        parameters: [
                            {
                                name: "id",
                                in: "path",
                                required: true,
                            },
                            {
                                name: "body",
                                in: "body",
                                required: false,
                                type: "object",
                            },
                        ],
                    },
                    get: {
                        operationId: "testGet",
                        produces: ["application/json"],
                        parameters: [
                            {
                                name: "id",
                                in: "path",
                                required: true,
                            },
                        ],
                    },
                },
            },
        },
    ]
    // const foo = openApiList[0]
    // const pathOptions = []
    const pathOptStrings = Object.values(openApiList[0].paths).map(Object.values).flat()

        // .map((pathKey) => {
        //     return Object.keys((openApiList[0].paths as any)[pathKey]).map((methodKey) => {
        //         return (openApiList[0].paths as any)[pathKey][methodKey].operationId
        //     })
        // })
        // .flat()

    console.log(pathOptStrings)
    const pathOpts = pathOptStrings.map((s) => ({
        key: s,
        value: s,
        children: s
    }))
    console.log(pathOpts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment