Skip to content

Commit

Permalink
Merge pull request #96 from JakkuSakura/fix-redoc-error
Browse files Browse the repository at this point in the history
Fix inconsistency in extracting schema and cause redoc to crash
  • Loading branch information
Wicpar authored Dec 14, 2023
2 parents 24ffb72 + f2beabc commit 318f2ee
Showing 1 changed file with 20 additions and 17 deletions.
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

0 comments on commit 318f2ee

Please sign in to comment.