[go: nahoru, domu]

Skip to content

Commit

Permalink
fix bugs: failing openapi import and bad code transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrosner committed May 29, 2024
1 parent bf3ab1a commit bac9d79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 6 additions & 2 deletions client/src/utils/httpsnippet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,16 @@ function generateHTTPSnippet(
value: header.value,
};
});
const uri = interpolated.data.uri ?? 'https://example.com';
const url = uri.startsWith('http') ? uri : `http://${uri}`;
const opts: any = {
method: interpolated.data.method ?? 'GET',
url: interpolated.data.uri ?? 'https://example.com',
url,
headers: headers ?? [],
postData,
};
if (opts.method !== 'GET') {
opts.postData = postData;
}
const snippet = new HTTPSnippet(opts);
const res = snippet.convert(target, client);
if (typeof res !== 'string') {
Expand Down
16 changes: 13 additions & 3 deletions server/src/main/kotlin/com/espero/yaade/services/OpenApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package com.espero.yaade.services

import com.espero.yaade.model.db.CollectionDb
import com.espero.yaade.model.db.RequestDb
import com.espero.yaade.server.Server
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.Operation
import io.vertx.core.impl.logging.LoggerFactory
import io.vertx.core.json.JsonArray
import io.vertx.core.json.JsonObject
import org.openapitools.codegen.examples.ExampleGenerator

object OpenApiService {

private val log = LoggerFactory.getLogger(Server::class.java)

private fun extractRequestFromOperation(
path: String,
basePath: String,
Expand Down Expand Up @@ -48,10 +52,16 @@ object OpenApiService {
val mediaType = mediaTypes[0]
val schema = operation.requestBody.content[mediaType]?.schema

val examples = exampleGenerator.generate(null, mediaTypes, schema)
if (examples.isNotEmpty()) {
body = examples[0]["example"]
try {
val examples = exampleGenerator.generate(null, mediaTypes, schema)
if (examples.isNotEmpty()) {
body = examples[0]["example"]
}
} catch (e: Exception) {
// NOTE: we don't want to crash the whole thing if we can't generate an example
log.error("Error generating example for request body", e)
}

}
}

Expand Down

0 comments on commit bac9d79

Please sign in to comment.