Skip to content

Commit

Permalink
get rid of x prefix in code
Browse files Browse the repository at this point in the history
  • Loading branch information
maximpn committed Jun 6, 2024
1 parent 23c2018 commit 4dd4a79
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions packages/kbn-openapi-bundler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ used in the OpenAPI specification files. The package can be used for API documen
- Omit parts of schemas that are hidden behind a feature flag (e.g. a new property added to an existing response schema).
- Omit custom OpenAPI attributes from the bundle, such as `x-codegen-enabled`, `x-internal`, `x-modify` and `x-labels`.
- Include only dedicated OpenAPI operation objects (a.k.a HTTP verbs) into the result bundle by labeling them via `x-labels`
and using `includeXLabels` bundler option, e.g. produce separate ESS and Serverless bundles
and using `includeLabels` bundler option, e.g. produce separate ESS and Serverless bundles
- Transform the target schema according to the custom OpenAPI attributes, such as `x-modify`.
- Resolve references, inline some of them and merge `allOf` object schemas for better readability. The bundled file contains only local references and paths.
- Group OpenAPI specs by version (OpenAPI's `info.version`) and produce a separate bundle for each group
Expand Down Expand Up @@ -48,11 +48,11 @@ bundle({
},
// Bundler options (optional)
options: {
// Optional `includeXLabels` allow to produce Serverless dedicated bundle by including only
// Optional `includeLabels` allow to produce Serverless dedicated bundle by including only
// OpenAPI operations objects (a.k.a HTTP verbs) labeled with specified labels, e.g. `serverless`.
// It requires labeling relevant operations objects with labels you want to be included, in the example
// below it should be a `serverless` label.
includeXLabels: ['serverless'],
includeLabels: ['serverless'],
},
});
```
Expand Down Expand Up @@ -256,15 +256,15 @@ bundle({
'target/openapi/serverless/my_bundle_name_{version}.bundled.schema.yaml'
),
options: {
includeXLabels: ['serverless'],
includeLabels: ['serverless'],
},
});
bundle({
sourceGlob: join(ROOT, './**/*.schema.yaml'),
outputFilePath: join(ROOT, 'target/openapi/ess/my_bundle_name_{version}.bundled.schema.yaml'),
options: {
includeXLabels: ['ess'],
includeLabels: ['ess'],
},
});
```
Expand Down
8 changes: 4 additions & 4 deletions packages/kbn-openapi-bundler/src/bundler/bundle_document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
createMergeNonConflictingAllOfItemsProcessor,
createUnfoldSingleAllOfItemProcessor,
} from './process_document/document_processors/reduce_all_of_items';
import { createIncludeXLabelsProcessor } from './process_document/document_processors/include_x_labels';
import { createIncludeLabelsProcessor } from './process_document/document_processors/include_labels';
import { BundleRefProcessor } from './process_document/document_processors/bundle_refs';
import { RemoveUnusedComponentsProcessor } from './process_document/document_processors/remove_unused_components';

Expand All @@ -38,7 +38,7 @@ export interface BundledDocument extends ResolvedDocument {
}

interface BundleDocumentOptions {
includeXLabels?: string[];
includeLabels?: string[];
}

/**
Expand Down Expand Up @@ -89,8 +89,8 @@ export async function bundleDocument(
createUnfoldSingleAllOfItemProcessor(),
];

if (options?.includeXLabels) {
defaultProcessors.push(createIncludeXLabelsProcessor(options?.includeXLabels));
if (options?.includeLabels) {
defaultProcessors.push(createIncludeLabelsProcessor(options?.includeLabels));
}

const bundleRefsProcessor = new BundleRefProcessor(X_INLINE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { DocumentNodeProcessor } from './types/document_node_processor';
* Creates a node processor to include only OAS operation objects labeled
* with one or more of the provided via `labelsToInclude` labels.
*/
export function createIncludeXLabelsProcessor(labelsToInclude: string[]): DocumentNodeProcessor {
export function createIncludeLabelsProcessor(labelsToInclude: string[]): DocumentNodeProcessor {
if (labelsToInclude.length === 0) {
throw new Error('"labelsToInclude" must have at least one label.');
}
Expand All @@ -27,17 +27,17 @@ export function createIncludeXLabelsProcessor(labelsToInclude: string[]): Docume
// https://swagger.io/docs/specification/paths-and-operations/
return 'responses' in node;
};
const logUnsupportedNodeWarning = (location: string, xLabelsValue: unknown): void => {
const value = Array.isArray(xLabelsValue) ? xLabelsValue.join(', ') : xLabelsValue;
const logUnsupportedNodeWarning = (location: string, labelsValue: unknown): void => {
const value = Array.isArray(labelsValue) ? labelsValue.join(', ') : labelsValue;

logger.warning(
`"${X_LABELS}: ${value}" in ${location} is ignored since "${X_LABELS}" is supported only for Operation objects.`
);
};
const logInvalidLabelsValueWarning = (location: string, xLabelsValue: unknown) => {
const logInvalidLabelsValueWarning = (location: string, labelsValue: unknown) => {
logger.warning(
`"${X_LABELS}" in ${location} is ignored since an array of labels is expected but got "${JSON.stringify(
xLabelsValue
labelsValue
)}".`
);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/kbn-openapi-bundler/src/openapi_bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface BundlerConfig {
}

interface BundleOptions {
includeXLabels?: string[];
includeLabels?: string[];
specInfo?: Omit<Partial<OpenAPIV3.InfoObject>, 'version'>;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ async function resolveDocuments(
schemaFilePaths.map(async (schemaFilePath) => {
try {
const resolvedDocument = await bundleDocument(schemaFilePath, {
includeXLabels: options?.includeXLabels,
includeLabels: options?.includeLabels,
});

logger.debug(`Processed ${chalk.bold(basename(schemaFilePath))}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('OpenAPI Bundler - specs with multiple modifications', () => {
const bundledFilePathTemplate = join(outputFolderPath, 'oas-test-bundle-{version}.yaml');

await bundleFolder(folderToBundlePath, bundledFilePathTemplate, {
includeXLabels: ['include'],
includeLabels: ['include'],
});

const [bundledSpec] = Object.values(readBundledSpecs(outputFolderPath));
Expand Down
10 changes: 5 additions & 5 deletions packages/kbn-openapi-bundler/tests/include_labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('OpenAPI Bundler - include labeled operations', () => {
1: spec,
},
{
includeXLabels: [label],
includeLabels: [label],
}
)
);
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('OpenAPI Bundler - include labeled operations', () => {
1: spec,
},
{
includeXLabels: ['labelA', 'labelB'],
includeLabels: ['labelA', 'labelB'],
}
)
);
Expand Down Expand Up @@ -180,7 +180,7 @@ describe('OpenAPI Bundler - include labeled operations', () => {
1: spec,
},
{
includeXLabels: ['labelA', 'labelB'],
includeLabels: ['labelA', 'labelB'],
}
)
);
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('OpenAPI Bundler - include labeled operations', () => {
1: spec,
},
{
includeXLabels: ['labelA'],
includeLabels: ['labelA'],
}
)
);
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('OpenAPI Bundler - include labeled operations', () => {
1: spec,
},
{
includeXLabels: ['labelA'],
includeLabels: ['labelA'],
}
)
);
Expand Down

0 comments on commit 4dd4a79

Please sign in to comment.