Skip to content

Commit

Permalink
Merge pull request #11 from CharlyJazz/fix/improve-support
Browse files Browse the repository at this point in the history
fix when content is */* and type string or integer
  • Loading branch information
CharlyJazz authored Aug 20, 2023
2 parents 2b707d0 + 86e0205 commit 4da5143
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ yarn-error.log*

build.zip
gh-pages
gh-pages.pub
gh-pages.pub

filestests/
5 changes: 4 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"short_name": "Prettyrest",
"name": "Pretty Rest API Documentacion",
"description": "Extension to render a OPEN API 3 REST Documentation uploading the JSON File",
"author": "carlosjazzc1@gmail.com",
"manifest_version": 3,
"version": "0.0.1",
"icons": {
Expand All @@ -13,5 +15,6 @@
"default_title": "Pretty Rest API Documentacion",
"default_popup": "index.html"
},
"permissions": ["storage"]
"permissions": ["storage"],
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2IX3K1BLRNKUrQ3E90iPfbgAAOsgca+mtoriRnnddu2078ixyGd1Cu0WD8n2mE7PMBNS9/UAEQYJdH2OTSaABhHbx8jJns3I7vaWRmeaCK+GXf3zjtpZCTosUtIQxJpLPAC1l1Cy/wCnVsXbG+ebAJmojqzNqeQG3e3zUEr4dxKLBEk2YSs3wQVoKbGQRQJhGD8j/8ekRAmcsaA5FoSOKt7HGsuQCrtpyoIPaQ0qvQ3/SOrjmDyEAOm1HQveiogN5ZDXybSJulcnfORONThK1CU8Lyo1x5oigsaAlTo8ywCXG8rC6FocFHXa1UtDOo/09rUwBoAmbGThJ0gV8XgU6wIDAQAB"
}
2 changes: 0 additions & 2 deletions src/lib/adapter-oa3/adapter/AdaptarOA3FromFileInput.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { OpenAPIV3 } from "openapi-types";
import { Resolver } from "@stoplight/json-ref-resolver";
import getObjectSchema from "./getObjectSchema";
import getObjectExample from "./getObjectExample";
import getArrayOfEndpoints from "./getArrayOfEndpoints";
import { capitalizeFirstWord } from "../../../utils/capitalize";
import { AdaptarOA3 } from "./AdaptarOA3";
Expand Down
11 changes: 6 additions & 5 deletions src/lib/adapter-oa3/adapter/getBodyRequestExample.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// @ts-nocheck

import { OpenAPIV3 } from "openapi-types";

const getSchema = (requestBodyObject: OpenAPIV3.RequestBodyObject) =>
requestBodyObject?.content?.["application/json"]?.schema ||
requestBodyObject?.content?.["multipart/form-data"]?.schema;
import getSchema from "./getSchema";

/*
Get Object From 'bodyRequest' attribute
Expand All @@ -13,7 +10,7 @@ const getBodyRequestExample: RawExample = (
requestBodyObject: OpenAPIV3.RequestBodyObject
): RawExample => {
const bodyRequest: RawExample = {};
const schema = getSchema(requestBodyObject) as OpenAPIV3.SchemaObject;
const schema = getSchema(requestBodyObject);
if (schema) {
const entries = Object.entries(
schema.properties || schema?.items?.properties || {}
Expand All @@ -23,6 +20,10 @@ const getBodyRequestExample: RawExample = (
value = value as OpenAPIV3.NonArraySchemaObject;
if (value.example) {
bodyRequest[key] = value.example;
} else if (value.type === "string") {
bodyRequest[key] = `A string`;
} else if (value.type === "integer") {
bodyRequest[key] = 0;
} else if (value.type === "array" && value.items && value.items.example) {
bodyRequest[key] = [value.items.example];
} else if (value.type === "object" && value.properties) {
Expand Down
5 changes: 4 additions & 1 deletion src/lib/adapter-oa3/adapter/getObjectSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import { OpenAPIV3 } from "openapi-types";

const getObjectSchema = (
doc: OpenAPIV3.Document | OpenAPIV3.BaseSchemaObject,
doc:
| OpenAPIV3.Document
| OpenAPIV3.BaseSchemaObject
| OpenAPIV3.ReferenceObject,
schemaName: string
): SchemaItem[] => {
const objectSchema: SchemaItem[] = [];
Expand Down
14 changes: 5 additions & 9 deletions src/lib/adapter-oa3/adapter/getParameters.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import { OpenAPIV3 } from "openapi-types";
import getObjectSchema from "./getObjectSchema";
import getSchema from "./getSchema";

const getParameters = (
parameters: OpenAPIV3.ParameterObject[] | undefined,
method: HTTP_METHOD,
requestBody: OpenAPIV3.RequestBodyObject | undefined
): SchemaParameters => {
// console.log(parameters);
const inHeader: SchemaItem[] = [];
const inPath: SchemaItem[] = [];
const inQuery: SchemaItem[] = [];
const inBody: SchemaItem[] = [];

// https://swagger.io/docs/specification/describing-request-body/
if (["POST", "PUT", "PATCH"].includes(method) && requestBody) {
inBody.push(
...getObjectSchema(
(requestBody as OpenAPIV3.RequestBodyObject)?.content?.[
"application/json"
]?.schema as OpenAPIV3.BaseSchemaObject,
""
)
);
const schema = getSchema(requestBody as OpenAPIV3.RequestBodyObject);
if (schema) {
inBody.push(...getObjectSchema(schema, ""));
}
}

if (parameters && Array.isArray(parameters) && parameters?.length) {
Expand Down
8 changes: 8 additions & 0 deletions src/lib/adapter-oa3/adapter/getSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { OpenAPIV3 } from "openapi-types";

const getSchema = (requestBodyObject: OpenAPIV3.RequestBodyObject) =>
requestBodyObject?.content?.["application/json"]?.schema ||
requestBodyObject?.content?.["multipart/form-data"]?.schema ||
requestBodyObject?.content?.["*/*"]?.schema;

export default getSchema;

0 comments on commit 4da5143

Please sign in to comment.