Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Splitting summary and description in OpenAPI output #2608

Merged
merged 9 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions compiler-rs/clients_schema_to_openapi/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ pub fn add_endpoint(

parameters.append(&mut query_params.clone());

let sum_desc = split_summary_desc(endpoint.description.clone());

// Create the operation, it will be repeated if we have several methods
let operation = openapiv3::Operation {
tags: vec![endpoint.name.clone()],
summary: Some(endpoint.description.clone()),
description: Some(endpoint.description.clone()),
summary: Some(sum_desc.summary),
description: Some(sum_desc.description),
external_docs: tac.convert_external_docs(endpoint),
operation_id: None, // set in clone_operation below with operation_counter
parameters,
Expand Down Expand Up @@ -311,6 +313,25 @@ fn get_path_parameters(template: &str) -> Vec<&str> {
result
}

fn split_summary_desc(desc: String) -> SplitDesc{
l-trotta marked this conversation as resolved.
Show resolved Hide resolved
let mut parts = desc.split(['.','\n',':']);
l-trotta marked this conversation as resolved.
Show resolved Hide resolved
let first_line = parts.next().unwrap_or_else(|| "");
l-trotta marked this conversation as resolved.
Show resolved Hide resolved

let new_desc = desc.replace(first_line,"");
let trim = new_desc.trim();
let remove_period = trim.strip_prefix('.').unwrap_or_else(|| trim);
let remove_column = remove_period.strip_prefix(':').unwrap_or_else(|| remove_period);
l-trotta marked this conversation as resolved.
Show resolved Hide resolved
SplitDesc {
summary: String::from(first_line.trim()),
description: String::from(remove_column.trim())
}
}

struct SplitDesc {
summary: String,
description: String
l-trotta marked this conversation as resolved.
Show resolved Hide resolved
}

#[cfg(test)]
Anaethelion marked this conversation as resolved.
Show resolved Hide resolved
mod tests {
use super::*;
Expand Down
Binary file modified compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions compiler/src/transform/schema-to-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ import { readFileSync, writeFileSync } from 'fs'

const inputPath = argv.input ?? join(__dirname, '..', '..', '..', 'output', 'schema', 'schema.json')
const outputPath = argv.output ?? join(__dirname, '..', '..', '..', 'output', 'openapi', 'elasticsearch-serverless-openapi.json')
const outputPathStack = argv.output ?? join(__dirname, '..', '..', '..', 'output', 'openapi', 'elasticsearch-openapi.json')

const inputText = readFileSync(
inputPath,
{ encoding: 'utf8' }
)

const output = convert_schema_to_openapi(inputText, 'serverless')
const outputStack = convert_schema_to_openapi(inputText, 'stack')

writeFileSync(
outputPath,
output,
'utf8'
)

writeFileSync(
outputPathStack,
outputStack,
'utf8'
)
Loading
Loading