Skip to content

Commit

Permalink
fix: ensure we apply audience-based filtering to examples as well (#3043
Browse files Browse the repository at this point in the history
)

* add in audiences to seed and allow passing config to custom fixtures

* remove these logs

* ensure customer test works

* cr

* update these unrelated tests

* update tests
  • Loading branch information
armandobelardo authored Feb 26, 2024
1 parent 9f1b284 commit 518461f
Show file tree
Hide file tree
Showing 22 changed files with 2,214 additions and 1,184 deletions.
872 changes: 729 additions & 143 deletions packages/cli/generation/ir-generator/src/__test__/__snapshots__/enum.txt

Large diffs are not rendered by default.

409 changes: 409 additions & 0 deletions packages/cli/generation/ir-generator/src/filterExamples.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { noop, visitObject } from "@fern-api/core-utils";
import { dirname, join, RelativeFilePath } from "@fern-api/fs-utils";
import { GenerationLanguage } from "@fern-api/generators-configuration";
import {
ExampleType,
HttpEndpoint,
IntermediateRepresentation,
PathParameterLocation,
Expand Down Expand Up @@ -30,6 +31,7 @@ import { convertTypeDeclaration } from "./converters/type-declarations/convertTy
import { constructFernFileContext, constructRootApiFileContext, FernFileContext } from "./FernFileContext";
import { FilteredIr } from "./filtered-ir/FilteredIr";
import { IrGraph } from "./filtered-ir/IrGraph";
import { filterEndpointExample, filterExampleType } from "./filterExamples";
import { formatDocs } from "./formatDocs";
import { IdGenerator } from "./IdGenerator";
import { PackageTreeGenerator } from "./PackageTreeGenerator";
Expand Down Expand Up @@ -408,13 +410,17 @@ function filterIntermediateRepresentationForAudiences(
const filteredTypesAndProperties = Object.fromEntries(
Object.entries(filteredTypes).map(([typeId, typeDeclaration]) => {
const filteredProperties = [];
typeDeclaration.examples = typeDeclaration.examples
.map((example) => filterExampleType({ filteredIr, exampleType: example }))
.filter((ex) => ex !== undefined) as ExampleType[];
if (typeDeclaration.shape.type === "object") {
for (const property of typeDeclaration.shape.properties) {
const hasProperty = filteredIr.hasProperty(typeId, property.name.wireValue);
if (hasProperty) {
filteredProperties.push(property);
}
}

return [
typeId,
{
Expand All @@ -441,6 +447,9 @@ function filterIntermediateRepresentationForAudiences(
endpoints: httpService.endpoints
.filter((httpEndpoint) => filteredIr.hasEndpoint(httpEndpoint))
.map((httpEndpoint) => {
httpEndpoint.examples = httpEndpoint.examples.map((example) =>
filterEndpointExample({ filteredIr, example })
);
if (httpEndpoint.requestBody?.type === "inlinedRequestBody") {
return {
...httpEndpoint,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70879,7 +70879,7 @@ exports[`open api parser aries parse open api 1`] = `
"type": "primitive",
"value": {
"type": "datetime",
"value": "2021-03-29T05:22:19.000Z",
"value": "2021-03-29 05:22:19+00:00",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,14 @@ The parameter should map to a JSON encoded list of strings.
"type": "primitive",
"value": {
"type": "datetime",
"value": "2024-01-15T09:30:00.000Z",
"value": "2024-01-15T09:30:00Z",
},
},
"created": {
"type": "primitive",
"value": {
"type": "datetime",
"value": "2024-01-15T09:30:00.000Z",
"value": "2024-01-15T09:30:00Z",
},
},
"id": {
Expand Down
310 changes: 155 additions & 155 deletions packages/cli/openapi-parser/src/__test__/__snapshots__/belvo.test.ts.snap

Large diffs are not rendered by default.

Loading

0 comments on commit 518461f

Please sign in to comment.