feat: publish canonical source contracts
All checks were successful
Mostovik Backend CI/CD / Tests and lint (push) Successful in 3m3s
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Successful in 5m2s
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been skipped
Mostovik Backend CI/CD / Deploy dev (push) Successful in 2m53s
All checks were successful
Mostovik Backend CI/CD / Tests and lint (push) Successful in 3m3s
Mostovik Backend CI/CD / Build linux/amd64 release images (push) Successful in 5m2s
Mostovik Backend CI/CD / Deploy and verify internal main (push) Has been skipped
Mostovik Backend CI/CD / Deploy dev (push) Successful in 2m53s
This commit is contained in:
@@ -25,6 +25,10 @@ const variants = [
|
||||
['SmeSupport', 'government_support', 'fns_sme_support_recipients', 'sme_support_measure', 'SmeSupportRecord'],
|
||||
['SroMembership', 'sro_membership', 'sro_membership_check', 'sro_membership', 'SroMembership'],
|
||||
];
|
||||
const extendedVariants = [
|
||||
['IntegratedStructure', 'integrated_structure_documents', 'integrated_structures', 'integrated_structure', 'IntegratedStructure'],
|
||||
['FedresursCompanyProfile', 'fedresurs_company_profile', 'fedresurs_company_profile', 'company_profile', 'FedresursCompanyProfile'],
|
||||
];
|
||||
const requiredRecordFields = [
|
||||
'uid', 'source_group', 'source', 'record_type', 'external_id', 'title', 'status',
|
||||
'created_at', 'updated_at', 'organization', 'payload',
|
||||
@@ -32,7 +36,7 @@ const requiredRecordFields = [
|
||||
const listOperation = document.paths['/api/v2/organization-source-records/']?.get;
|
||||
if (!listOperation) throw new Error('Source records list operation missing');
|
||||
const groupParameter = listOperation.parameters.find((parameter) => parameter.name === 'source_group');
|
||||
const legacyGroups = groupParameter.schema.enum.filter((group) => !variants.some((variant) => variant[1] === group));
|
||||
const legacyGroups = groupParameter.schema.enum.filter((group) => ![...variants, ...extendedVariants].some((variant) => variant[1] === group));
|
||||
|
||||
schemas.PublishedSourceRecordOrganization = clone(schemas.OrganizationSourceRecordOrganization);
|
||||
schemas.PublishedSourceRecordOrganization.required = ['uid', 'name', 'inn', 'ogrn', 'okpo'];
|
||||
@@ -106,6 +110,80 @@ for (const name of ['OrganizationSourceRecordListResponse', 'SourceRecordMeta',
|
||||
}
|
||||
schemas.OrganizationSourceRecordListResponse.properties.errors = { type: 'object', nullable: true, enum: [null] };
|
||||
|
||||
// The two richer source payloads have stable public DTOs in addition to the
|
||||
// generic DRF JSONField. Keep these schemas beside the canonical converter so
|
||||
// both backend /openapi.json and the frontend client come from one contract.
|
||||
const extensions = JSON.parse(readFileSync(resolve(base, 'tools/openapi/source-record-extensions.json'), 'utf8'));
|
||||
for (const [name, schema] of Object.entries(extensions)) {
|
||||
if (schemas[name]) throw new Error(`Duplicate source schema: ${name}`);
|
||||
schemas[name] = schema;
|
||||
}
|
||||
for (const [prefix, group, source, recordType, payloadPrefix] of extendedVariants) {
|
||||
for (const [schemaName, kind] of [
|
||||
['OrganizationSourceRecordList', 'List'],
|
||||
['OrganizationSourceRecord', 'Detail'],
|
||||
]) {
|
||||
const variantName = `${prefix}Record${kind}`;
|
||||
const payloadName = `${payloadPrefix}${kind}Payload`;
|
||||
if (!schemas[payloadName]) throw new Error(`Named payload missing: ${payloadName}`);
|
||||
const schema = clone(schemas[`Legacy${schemaName}`]);
|
||||
schema.required = [...new Set([...(schema.required || []), ...requiredRecordFields])];
|
||||
schema.properties.source_group = { type: 'string', enum: [group] };
|
||||
schema.properties.source = { type: 'string', enum: [source] };
|
||||
schema.properties.record_type = { type: 'string', enum: [recordType] };
|
||||
schema.properties.status = { type: 'string' };
|
||||
schema.properties.payload = ref(payloadName);
|
||||
schema.properties.organization = ref('SroSourceRecordOrganization');
|
||||
schemas[variantName] = schema;
|
||||
schemas[schemaName].oneOf.push(ref(variantName));
|
||||
schemas[schemaName].discriminator.mapping[group] = ref(variantName).$ref;
|
||||
}
|
||||
}
|
||||
|
||||
const attachmentPath = document.paths['/api/v2/organization-source-records/{uid}/documents/{document_id}/attachment/'];
|
||||
if (!attachmentPath?.get) throw new Error('Integrated attachment endpoint missing');
|
||||
attachmentPath.get.responses['200'] = {
|
||||
description: 'Immutable RTF attachment',
|
||||
content: { 'application/rtf': { schema: { type: 'string', format: 'binary' } } },
|
||||
};
|
||||
attachmentPath.get.responses['409'] = {
|
||||
description: 'attachment_unavailable',
|
||||
content: { 'application/json': { schema: ref('AttachmentUnavailableError') } },
|
||||
};
|
||||
|
||||
document.paths['/api/v1/parsers/upload/fedresurs_company_profile/'] = {
|
||||
post: {
|
||||
operationId: 'api_v1_parsers_upload_fedresurs_company_profile_create',
|
||||
summary: 'Fedresurs public UI does not accept file uploads',
|
||||
description: 'Use the Fedresurs refresh endpoint instead of multipart upload.',
|
||||
responses: {
|
||||
'405': {
|
||||
description: 'upload_not_supported',
|
||||
content: { 'application/json': { schema: ref('FedresursUploadNotSupportedError') } },
|
||||
},
|
||||
},
|
||||
tags: ['Parser Management'],
|
||||
},
|
||||
};
|
||||
schemas.FedresursUploadNotSupportedError = {
|
||||
type: 'object',
|
||||
required: ['success', 'errors'],
|
||||
properties: {
|
||||
success: { type: 'boolean', enum: [false] },
|
||||
errors: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
required: ['code', 'message'],
|
||||
properties: {
|
||||
code: { type: 'string', enum: ['upload_not_supported'] },
|
||||
message: { type: 'string' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Swagger's pagination inspector emits required:[] for legacy envelopes. Omitting
|
||||
// this empty constraint preserves its meaning and is valid in OpenAPI 3.0.
|
||||
function removeEmptyRequired(value) {
|
||||
|
||||
Reference in New Issue
Block a user