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

Fix inconsistency in extracting schema and cause redoc to crash #96

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all 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
37 changes: 20 additions & 17 deletions crates/aide/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,7 @@ pub fn on_error(handler: impl Fn(Error) + 'static) {
/// [`OpenApi`]: crate::openapi::OpenApi
pub fn extract_schemas(extract: bool) {
in_context(|ctx| {
if extract {
ctx.schema = SchemaGenerator::new(SchemaSettings::draft07().with(|s| {
s.inline_subschemas = false;
s.definitions_path = "#/components/schemas/".into();
}));
ctx.extract_schemas = true;
} else {
ctx.schema = SchemaGenerator::new(SchemaSettings::draft07().with(|s| {
s.inline_subschemas = true;
}));
ctx.extract_schemas = false;
}
ctx.set_extract_schemas(extract)
});
}

Expand Down Expand Up @@ -143,22 +132,36 @@ impl GenContext {
}
}

Self {
schema: SchemaGenerator::new(
SchemaSettings::draft07().with(|s| s.inline_subschemas = false),
),
let mut this = Self {
schema: SchemaGenerator::new(SchemaSettings::draft07()),
infer_responses: true,
all_error_responses: false,
extract_schemas: true,
show_error: default_error_filter,
error_handler: None,
no_content_status,
}
};
this.set_extract_schemas(true);
this
}

pub(crate) fn reset_error_filter(&mut self) {
self.show_error = default_error_filter;
}
fn set_extract_schemas(&mut self, extract: bool) {
if extract {
self.schema = SchemaGenerator::new(SchemaSettings::draft07().with(|s| {
s.inline_subschemas = false;
s.definitions_path = "#/components/schemas/".into();
}));
self.extract_schemas = true;
} else {
self.schema = SchemaGenerator::new(SchemaSettings::draft07().with(|s| {
s.inline_subschemas = true;
}));
self.extract_schemas = false;
}
}

/// Add an error in the current context.
#[tracing::instrument(skip_all)]
Expand Down