Skip to content

Commit a83a2fe

Browse files
[Form Recognizer] API consistency and naming (Azure#22482)
* DocumentModelPoller * CreateModelOptions * more feedback * regenerate * build failures * API Report * swagger * documentModelId revert * feedback * API view * GetOperationResponse * ErrorModel, * feedback * build fixes * format
1 parent d16d099 commit a83a2fe

31 files changed

+556
-671
lines changed

sdk/formrecognizer/ai-form-recognizer/review/ai-form-recognizer.api.md

Lines changed: 93 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ export interface AnalyzeDocumentOptions<Result = AnalyzeResult<AnalyzedDocument>
5252

5353
// @public
5454
export interface AnalyzeResult<Document = AnalyzedDocument> extends AnalyzeResultCommon {
55-
documents: Document[];
56-
keyValuePairs: DocumentKeyValuePair[];
57-
languages: DocumentLanguage[];
58-
pages: DocumentPage[];
59-
paragraphs: DocumentParagraph[];
60-
styles: DocumentStyle[];
61-
tables: DocumentTable[];
55+
documents?: Document[];
56+
keyValuePairs?: DocumentKeyValuePair[];
57+
languages?: DocumentLanguage[];
58+
pages?: DocumentPage[];
59+
paragraphs?: DocumentParagraph[];
60+
styles?: DocumentStyle[];
61+
tables?: DocumentTable[];
6262
}
6363

6464
// @public
@@ -80,12 +80,20 @@ export interface ArrayFieldSchema<Item extends Readonly<FieldSchema> = Readonly<
8080
export { AzureKeyCredential }
8181

8282
// @public
83-
export interface BoundingRegion extends HasBoundingPolygon {
84-
pageNumber: number;
83+
export interface BeginBuildModelOptions extends CreateModelOptions {
84+
}
85+
86+
// @public
87+
export interface BeginComposeModelOptions extends CreateModelOptions {
8588
}
8689

8790
// @public
88-
export interface BuildModelOptions extends OperationOptions, CommonModelCreationOptions, PollerOptions<TrainingPollOperationState> {
91+
export interface BeginCopyModelOptions extends OperationOptions, PollerOptions<TrainingPollOperationState> {
92+
}
93+
94+
// @public
95+
export interface BoundingRegion extends HasBoundingPolygon {
96+
pageNumber: number;
8997
}
9098

9199
// @public
@@ -197,7 +205,7 @@ export interface CopyAuthorization {
197205
}
198206

199207
// @public
200-
export interface CopyModelOptions extends OperationOptions, PollerOptions<TrainingPollOperationState> {
208+
export interface CreateModelOptions extends OperationOptions, CommonModelCreationOptions, PollerOptions<TrainingPollOperationState> {
201209
}
202210

203211
// @public
@@ -377,16 +385,16 @@ export class DocumentModelAdministrationClient {
377385
constructor(endpoint: string, credential: TokenCredential, options?: DocumentModelAdministrationClientOptions);
378386
constructor(endpoint: string, credential: KeyCredential, options?: DocumentModelAdministrationClientOptions);
379387
constructor(endpoint: string, credential: KeyCredential | TokenCredential, options?: DocumentModelAdministrationClientOptions);
380-
beginBuildModel(modelId: string, containerUrl: string, buildMode: DocumentModelBuildMode, options?: BuildModelOptions): Promise<TrainingPoller>;
381-
beginComposeModel(modelId: string, componentModelIds: Iterable<string>, options?: BuildModelOptions): Promise<TrainingPoller>;
382-
beginCopyModelTo(sourceModelId: string, authorization: CopyAuthorization, options?: CopyModelOptions): Promise<TrainingPoller>;
388+
beginBuildModel(modelId: string, containerUrl: string, buildMode: DocumentModelBuildMode, options?: BeginBuildModelOptions): Promise<DocumentModelPoller>;
389+
beginComposeModel(modelId: string, componentModelIds: Iterable<string>, options?: BeginComposeModelOptions): Promise<DocumentModelPoller>;
390+
beginCopyModelTo(sourceModelId: string, authorization: CopyAuthorization, options?: BeginCopyModelOptions): Promise<DocumentModelPoller>;
383391
deleteModel(modelId: string, options?: DeleteModelOptions): Promise<void>;
384392
getCopyAuthorization(destinationModelId: string, options?: GetCopyAuthorizationOptions): Promise<CopyAuthorization>;
385-
getInfo(options?: GetInfoOptions): Promise<GetInfoResponse>;
386-
getModel(modelId: string, options?: GetModelOptions): Promise<ModelInfo>;
393+
getModel(modelId: string, options?: GetModelOptions): Promise<DocumentModelInfo>;
387394
getOperation(operationId: string, options?: GetOperationOptions): Promise<OperationInfo>;
388-
listModels(options?: ListModelsOptions): PagedAsyncIterableIterator<ModelSummary>;
389-
listOperations(options?: ListOperationsOptions): PagedAsyncIterableIterator<OperationInfo>;
395+
getResourceInfo(options?: GetResourceInfoOptions): Promise<ResourceInfo>;
396+
listModels(options?: ListModelsOptions): PagedAsyncIterableIterator<DocumentModelSummary>;
397+
listOperations(options?: ListOperationsOptions): PagedAsyncIterableIterator<OperationSummary>;
390398
}
391399

392400
// @public
@@ -402,6 +410,27 @@ export const DocumentModelBuildMode: {
402410
readonly Neural: "neural";
403411
};
404412

413+
// @public
414+
export interface DocumentModelInfo extends DocumentModelSummary {
415+
docTypes?: {
416+
[propertyName: string]: DocTypeInfo;
417+
};
418+
}
419+
420+
// @public
421+
export type DocumentModelPoller = PollerLike<TrainingPollOperationState, DocumentModelInfo>;
422+
423+
// @public
424+
export interface DocumentModelSummary {
425+
apiVersion?: string;
426+
createdDateTime: Date;
427+
description?: string;
428+
modelId: string;
429+
tags?: {
430+
[propertyName: string]: string;
431+
};
432+
}
433+
405434
// @public
406435
export interface DocumentNumberField extends DocumentValueField<number> {
407436
kind: "number";
@@ -531,6 +560,15 @@ export interface DocumentWord extends HasBoundingPolygon {
531560
// @public
532561
export type EnglishCapitalLetter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z";
533562

563+
// @public
564+
export interface ErrorModel {
565+
code: string;
566+
details?: ErrorModel[];
567+
innererror?: InnerError;
568+
message: string;
569+
target?: string;
570+
}
571+
534572
// @public
535573
export type FieldSchema = StringLikeFieldSchema | NumberFieldSchema | DateFieldSchema | ArrayFieldSchema | ObjectFieldSchema | StructuredStringFieldSchema | WellKnownObjectFieldSchema;
536574

@@ -552,28 +590,26 @@ export type FormRecognizerRequestBody = NodeJS.ReadableStream | Blob | ArrayBuff
552590

553591
// @public
554592
export interface GeneralDocumentResult extends LayoutResult {
555-
keyValuePairs: DocumentKeyValuePair[];
593+
keyValuePairs?: DocumentKeyValuePair[];
556594
}
557595

558596
// @public
559597
export interface GetCopyAuthorizationOptions extends OperationOptions, CommonModelCreationOptions {
560598
}
561599

562600
// @public
563-
export interface GetInfoOptions extends OperationOptions {
601+
export interface GetModelOptions extends OperationOptions {
564602
}
565603

566604
// @public
567-
export interface GetInfoResponse {
568-
customDocumentModels: CustomDocumentModelsInfo;
605+
export interface GetOperationOptions extends OperationOptions {
569606
}
570607

571608
// @public
572-
export interface GetModelOptions extends OperationOptions {
573-
}
609+
export type GetOperationResponse = OperationInfo;
574610

575611
// @public
576-
export interface GetOperationOptions extends OperationOptions {
612+
export interface GetResourceInfoOptions extends OperationOptions {
577613
}
578614

579615
// @public
@@ -669,6 +705,13 @@ export const IdentityDocumentSchema: {
669705
};
670706
};
671707

708+
// @public
709+
export interface InnerError {
710+
code: string;
711+
innererror?: InnerError;
712+
message?: string;
713+
}
714+
672715
// @public
673716
export type Invoice = ReifyPrebuiltSchema<typeof InvoiceSchema>;
674717

@@ -814,9 +857,9 @@ export const InvoiceSchema: {
814857

815858
// @public
816859
export interface LayoutResult {
817-
pages: DocumentPage[];
818-
styles: DocumentStyle[];
819-
tables: DocumentTable[];
860+
pages?: DocumentPage[];
861+
styles?: DocumentStyle[];
862+
tables?: DocumentTable[];
820863
}
821864

822865
// @public
@@ -830,13 +873,6 @@ export interface ListModelsOptions extends OperationOptions {
830873
export interface ListOperationsOptions extends OperationOptions {
831874
}
832875

833-
// @public
834-
export interface ModelInfo extends ModelSummary {
835-
docTypes?: {
836-
[propertyName: string]: DocTypeInfo;
837-
};
838-
}
839-
840876
// @public
841877
export interface ModelSchema {
842878
docTypes: {
@@ -849,17 +885,6 @@ export interface ModelSchema {
849885
modelId: string;
850886
}
851887

852-
// @public
853-
export interface ModelSummary {
854-
apiVersion?: string;
855-
createdDateTime: Date;
856-
description?: string;
857-
modelId: string;
858-
tags?: {
859-
[propertyName: string]: string;
860-
};
861-
}
862-
863888
// @public
864889
export interface NumberFieldSchema<Type extends "number" | "integer" = "number" | "integer"> {
865890
readonly type: Type;
@@ -876,7 +901,19 @@ export interface ObjectFieldSchema<Properties extends {
876901
}
877902

878903
// @public
879-
export interface OperationInfo {
904+
export interface OperationInfo extends OperationSummary {
905+
error?: ErrorModel;
906+
result?: Record<string, unknown>;
907+
}
908+
909+
// @public
910+
export type OperationKind = string;
911+
912+
// @public
913+
export type OperationStatus = "notStarted" | "running" | "failed" | "succeeded" | "canceled";
914+
915+
// @public
916+
export interface OperationSummary {
880917
apiVersion?: string;
881918
createdDateTime: Date;
882919
kind: OperationKind;
@@ -890,12 +927,6 @@ export interface OperationInfo {
890927
};
891928
}
892929

893-
// @public
894-
export type OperationKind = string;
895-
896-
// @public
897-
export type OperationStatus = "notStarted" | "running" | "failed" | "succeeded" | "canceled";
898-
899930
// @public
900931
export type ParagraphRole = string;
901932

@@ -1098,9 +1129,9 @@ export const PrebuiltModels: {
10981129

10991130
// @public
11001131
export interface ReadResult extends AnalyzeResultCommon {
1101-
languages: DocumentLanguage[];
1102-
pages: DocumentPage[];
1103-
styles: DocumentStyle[];
1132+
languages?: DocumentLanguage[];
1133+
pages?: DocumentPage[];
1134+
styles?: DocumentStyle[];
11041135
}
11051136

11061137
// @public
@@ -1472,6 +1503,11 @@ export type ReifyPrebuiltSchema<Schema extends Readonly<ModelSchema>> = {
14721503
};
14731504
}[keyof Schema["docTypes"]];
14741505

1506+
// @public
1507+
export interface ResourceInfo {
1508+
customDocumentModels: CustomDocumentModelsInfo;
1509+
}
1510+
14751511
// @public
14761512
export type SelectionMarkState = string;
14771513

@@ -1650,10 +1686,7 @@ export const TaxUsW2Schema: {
16501686
};
16511687

16521688
// @public
1653-
export type TrainingPoller = PollerLike<TrainingPollOperationState, ModelInfo>;
1654-
1655-
// @public
1656-
export interface TrainingPollOperationState extends PollOperationState<ModelInfo> {
1689+
export interface TrainingPollOperationState extends PollOperationState<DocumentModelInfo> {
16571690
apiVersion?: string;
16581691
createdOn: Date;
16591692
lastUpdatedOn: Date;

sdk/formrecognizer/ai-form-recognizer/samples-dev/analyzeBusinessCard.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,11 @@ async function main() {
3434
"https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/businessCard/business-card-english.jpg"
3535
);
3636

37-
const {
38-
documents: [result],
39-
} = await poller.pollUntilDone();
37+
const { documents } = await poller.pollUntilDone();
4038

4139
// Use of PrebuiltModels.Receipt above (rather than the raw model ID), adds strong typing of the model's output
42-
if (result) {
43-
const businessCard = result.fields;
40+
if (documents) {
41+
const businessCard = documents[0].fields;
4442
console.log("=== Business Card Information ===");
4543

4644
// There are more fields than just these few, and the model allows for multiple contact & company names as well as

sdk/formrecognizer/ai-form-recognizer/samples-dev/analyzeDocumentByModelId.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ async function main() {
2525
"https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/receipt/contoso-receipt.png"
2626
);
2727

28-
const {
29-
documents: [document],
30-
} = await poller.pollUntilDone();
31-
28+
const { documents } = await poller.pollUntilDone();
29+
const document = documents && documents[0];
3230
if (!document) {
3331
throw new Error("Expected at least one document in the result.");
3432
}

sdk/formrecognizer/ai-form-recognizer/samples-dev/analyzeIdentityDocument.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ async function main() {
3434
"https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/identityDocument/license.png"
3535
);
3636

37-
const {
38-
documents: [result],
39-
} = await poller.pollUntilDone();
40-
37+
const { documents } = await poller.pollUntilDone();
38+
const result = documents && documents[0];
4139
// Use of PrebuiltModels.Receipt above (rather than the raw model ID), adds strong typing of the model's output
4240
if (result) {
4341
// The identity document model has multiple document types, so we need to know which document type was actually

sdk/formrecognizer/ai-form-recognizer/samples-dev/analyzeInvoice.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ async function main() {
3333
"https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/invoice/sample_invoice.jpg"
3434
);
3535

36-
const {
37-
documents: [result],
38-
} = await poller.pollUntilDone();
36+
const { documents } = await poller.pollUntilDone();
3937

38+
const result = documents && documents[0];
4039
// Use of PrebuiltModels.Receipt above (rather than the raw model ID), adds strong typing of the model's output
4140
if (result) {
4241
const {

sdk/formrecognizer/ai-form-recognizer/samples-dev/analyzeReceipt.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ async function main() {
3333
"https://raw.githubusercontent.com/Azure/azure-sdk-for-js/main/sdk/formrecognizer/ai-form-recognizer/assets/receipt/contoso-receipt.png"
3434
);
3535

36-
const {
37-
documents: [result],
38-
} = await poller.pollUntilDone();
36+
const { documents } = await poller.pollUntilDone();
3937

38+
const result = documents && documents[0];
4039
// Use of PrebuiltModels.Receipt above (rather than the raw model ID), as it adds strong typing of the model's output
4140
if (result) {
4241
const { merchantName, items, total } = result.fields;

sdk/formrecognizer/ai-form-recognizer/samples-dev/analyzeReceiptByModelId.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ async function main() {
3838
);
3939
poller.onProgress((state) => console.log("Operation:", state.modelId, state.status));
4040

41-
const {
42-
documents: [result],
43-
} = await poller.pollUntilDone();
41+
const { documents } = await poller.pollUntilDone();
4442

43+
const result = documents && documents[0];
4544
if (result) {
4645
const receipt = result.fields;
4746
console.log("=== Receipt Information ===");

sdk/formrecognizer/ai-form-recognizer/samples-dev/analyzeW2TaxForm.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ async function main() {
3434

3535
const poller = await client.beginAnalyzeDocument(PrebuiltModels.TaxUsW2, file);
3636

37-
const {
38-
documents: [result],
39-
} = await poller.pollUntilDone();
37+
const { documents } = await poller.pollUntilDone();
4038

39+
const result = documents && documents[0];
4140
if (result) {
4241
const { employee, employer, controlNumber, taxYear, additionalInfo } = result.fields;
4342

sdk/formrecognizer/ai-form-recognizer/samples-dev/extractGeneralDocument.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function main() {
2828
// (associations between elements, such as labeled elements), and document entities.
2929
const { keyValuePairs } = await poller.pollUntilDone();
3030

31-
if (keyValuePairs.length <= 0) {
31+
if (!keyValuePairs || keyValuePairs.length <= 0) {
3232
console.log("No key-value pairs were extracted from the document.");
3333
} else {
3434
console.log("Key-Value Pairs:");

0 commit comments

Comments
 (0)