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:
File diff suppressed because one or more lines are too long
@@ -36,7 +36,7 @@ def test_discriminated_records_keep_named_ordering_and_old_operations(contract):
|
||||
schemas = contract["components"]["schemas"]
|
||||
for name in ("OrganizationSourceRecord", "OrganizationSourceRecordList"):
|
||||
record = schemas[name]
|
||||
assert len(record["oneOf"]) == 4
|
||||
assert len(record["oneOf"]) == 6
|
||||
assert record["discriminator"]["propertyName"] == "source_group"
|
||||
for group, record_type in (
|
||||
("budget_process_registry", "budget_registry_organization"),
|
||||
@@ -75,6 +75,36 @@ def test_discriminated_records_keep_named_ordering_and_old_operations(contract):
|
||||
)
|
||||
|
||||
|
||||
def test_extended_source_contracts_document_full_page_and_typed_errors(contract):
|
||||
schemas = contract["components"]["schemas"]
|
||||
for kind, payload_name in (
|
||||
("List", "IntegratedStructureListPayload"),
|
||||
("Detail", "IntegratedStructureDetailPayload"),
|
||||
):
|
||||
variant = schemas[f"IntegratedStructureRecord{kind}"]
|
||||
assert variant["properties"]["payload"]["$ref"].endswith(payload_name)
|
||||
fed_detail = schemas["FedresursCompanyProfileRecordDetail"]
|
||||
assert fed_detail["properties"]["payload"]["$ref"].endswith(
|
||||
"FedresursCompanyProfileDetailPayload"
|
||||
)
|
||||
assert (
|
||||
"rendered_page" in schemas["FedresursCompanyProfileDetailPayload"]["properties"]
|
||||
)
|
||||
|
||||
paths = contract["paths"]
|
||||
attachment = paths[
|
||||
"/api/v2/organization-source-records/{uid}/documents/{document_id}/attachment/"
|
||||
]["get"]
|
||||
assert "application/rtf" in attachment["responses"]["200"]["content"]
|
||||
assert attachment["responses"]["409"]["content"]["application/json"]["schema"][
|
||||
"$ref"
|
||||
].endswith("AttachmentUnavailableError")
|
||||
upload = paths["/api/v1/parsers/upload/fedresurs_company_profile/"]["post"]
|
||||
assert upload["responses"]["405"]["content"]["application/json"]["schema"][
|
||||
"$ref"
|
||||
].endswith("FedresursUploadNotSupportedError")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("source", "list_serializer", "detail_serializer"),
|
||||
[
|
||||
|
||||
@@ -7,6 +7,9 @@ The source is the actual DRF serializers and view annotations. `build.mjs` conve
|
||||
Swagger 2 to OpenAPI 3, adds the source-record discriminated variants and the named
|
||||
ordering enum with comma-separated ordering, then validates the resulting document.
|
||||
Do not edit `src/core/openapi.json` or generated TypeScript by hand.
|
||||
The public-UI Fedresurs and integrated-structure DTOs live in
|
||||
`source-record-extensions.json`; `build.mjs` adds their discriminated list/detail
|
||||
variants and typed upload/attachment errors to the generated contract.
|
||||
|
||||
From the backend root (Python dependencies installed with uv):
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
465
tools/openapi/source-record-extensions.json
Normal file
465
tools/openapi/source-record-extensions.json
Normal file
@@ -0,0 +1,465 @@
|
||||
{
|
||||
"AttachmentUnavailableError": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"success": {
|
||||
"type": "boolean",
|
||||
"enum": [
|
||||
false
|
||||
]
|
||||
},
|
||||
"errors": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"attachment_unavailable"
|
||||
]
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"code",
|
||||
"message"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"success",
|
||||
"errors"
|
||||
]
|
||||
},
|
||||
"IntegratedStructureSummary": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"events_count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"document_links_count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"unique_documents_count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"first_event_date": {
|
||||
"type": "string"
|
||||
},
|
||||
"latest_event_date": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"events_count",
|
||||
"document_links_count",
|
||||
"unique_documents_count",
|
||||
"first_event_date",
|
||||
"latest_event_date"
|
||||
]
|
||||
},
|
||||
"IntegratedStructureAttachment": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"available": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"download_allowed": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"filename": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"mime_type": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"sha256": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"size": {
|
||||
"type": "integer",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"available",
|
||||
"download_allowed",
|
||||
"filename",
|
||||
"mime_type",
|
||||
"sha256",
|
||||
"size"
|
||||
]
|
||||
},
|
||||
"IntegratedStructureDocument": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
},
|
||||
"number": {
|
||||
"type": "string"
|
||||
},
|
||||
"date": {
|
||||
"type": "string"
|
||||
},
|
||||
"dsp": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"have_text": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"consultant_web_url": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"attachment": {
|
||||
"$ref": "#/components/schemas/IntegratedStructureAttachment"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"name",
|
||||
"type",
|
||||
"number",
|
||||
"date",
|
||||
"dsp",
|
||||
"have_text",
|
||||
"attachment"
|
||||
]
|
||||
},
|
||||
"IntegratedStructureEvent": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"date": {
|
||||
"type": "string"
|
||||
},
|
||||
"note": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"documents_count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"documents": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/IntegratedStructureDocument"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"date",
|
||||
"note",
|
||||
"documents_count",
|
||||
"documents"
|
||||
]
|
||||
},
|
||||
"IntegratedStructureListPayload": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"structure": {
|
||||
"$ref": "#/components/schemas/IntegratedStructureSummary"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"structure"
|
||||
]
|
||||
},
|
||||
"IntegratedStructureDetailPayload": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"structure": {
|
||||
"$ref": "#/components/schemas/IntegratedStructureSummary"
|
||||
},
|
||||
"events": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/IntegratedStructureEvent"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"structure",
|
||||
"events"
|
||||
]
|
||||
},
|
||||
"FedresursRenderedNode": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"tag": {
|
||||
"type": "string"
|
||||
},
|
||||
"attributes": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"children": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/FedresursRenderedNode"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"tag",
|
||||
"attributes",
|
||||
"children"
|
||||
]
|
||||
},
|
||||
"FedresursRenderedPage": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"text": {
|
||||
"type": "string"
|
||||
},
|
||||
"tree": {
|
||||
"$ref": "#/components/schemas/FedresursRenderedNode"
|
||||
},
|
||||
"attributes": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"label": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"label",
|
||||
"value"
|
||||
]
|
||||
}
|
||||
},
|
||||
"links": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"text": {
|
||||
"type": "string"
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"text",
|
||||
"url"
|
||||
]
|
||||
}
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
},
|
||||
"page_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"reported_records_count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"records": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/FedresursRenderedPage"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"text",
|
||||
"tree",
|
||||
"attributes",
|
||||
"links"
|
||||
]
|
||||
},
|
||||
"FedresursStatus": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"code": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"is_active": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"code",
|
||||
"is_active"
|
||||
]
|
||||
},
|
||||
"FedresursCompanyProfileListPayload": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"fedresurs_guid": {
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
},
|
||||
"short_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"kpp": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"status": {
|
||||
"$ref": "#/components/schemas/FedresursStatus"
|
||||
},
|
||||
"executive_body_name": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"registration_date": {
|
||||
"type": "string",
|
||||
"format": "date",
|
||||
"nullable": true
|
||||
},
|
||||
"publication_count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"reorganization_count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"has_bankruptcy_information": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"captured_at": {
|
||||
"type": "string",
|
||||
"format": "date-time"
|
||||
},
|
||||
"source_url": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
},
|
||||
"sections": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"loaded",
|
||||
"empty",
|
||||
"not_available",
|
||||
"blocked",
|
||||
"schema_unverified"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"fedresurs_guid",
|
||||
"short_name",
|
||||
"kpp",
|
||||
"status",
|
||||
"registration_date",
|
||||
"publication_count",
|
||||
"reorganization_count",
|
||||
"has_bankruptcy_information",
|
||||
"captured_at",
|
||||
"source_url",
|
||||
"sections"
|
||||
]
|
||||
},
|
||||
"FedresursCompanyProfileDetailPayload": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"profile": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"full_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"inn": {
|
||||
"type": "string"
|
||||
},
|
||||
"ogrn": {
|
||||
"type": "string"
|
||||
},
|
||||
"kpp": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"registration_date": {
|
||||
"type": "string",
|
||||
"format": "date",
|
||||
"nullable": true
|
||||
},
|
||||
"status": {
|
||||
"$ref": "#/components/schemas/FedresursStatus"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"full_name",
|
||||
"inn",
|
||||
"ogrn",
|
||||
"status"
|
||||
],
|
||||
"additionalProperties": true
|
||||
},
|
||||
"rendered_sections": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/FedresursRenderedPage"
|
||||
}
|
||||
},
|
||||
"rendered_page": {
|
||||
"$ref": "#/components/schemas/FedresursRenderedPage"
|
||||
},
|
||||
"related_pages": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/components/schemas/FedresursRenderedPage"
|
||||
}
|
||||
},
|
||||
"message_details": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/FedresursRenderedPage"
|
||||
}
|
||||
},
|
||||
"lineage": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"profile",
|
||||
"rendered_page",
|
||||
"rendered_sections",
|
||||
"related_pages",
|
||||
"message_details",
|
||||
"lineage"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user