Skip to content

Commit 8401d88

Browse files
authored
Update swagger reference formrecognizer (Azure#18837)
1 parent d961e4b commit 8401d88

File tree

11 files changed

+509
-2455
lines changed

11 files changed

+509
-2455
lines changed

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClient.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.azure.ai.formrecognizer.implementation.Utility;
88
import com.azure.ai.formrecognizer.implementation.models.AnalyzeOperationResult;
99
import com.azure.ai.formrecognizer.implementation.models.ContentType;
10+
import com.azure.ai.formrecognizer.implementation.models.ContentType1;
1011
import com.azure.ai.formrecognizer.implementation.models.Language;
1112
import com.azure.ai.formrecognizer.implementation.models.Locale;
1213
import com.azure.ai.formrecognizer.implementation.models.OperationStatus;
@@ -235,9 +236,10 @@ isFieldElementsIncluded, new SourcePath().setSource(formUrl), context)
235236
recognizeCustomFormsOptions.getPollInterval(),
236237
streamActivationOperation(
237238
contentType -> service.analyzeWithCustomModelWithResponseAsync(UUID.fromString(modelId),
238-
contentType, form, length, isFieldElementsIncluded, context).map(response ->
239-
new FormRecognizerOperationResult(
240-
parseModelId(response.getDeserializedHeaders().getOperationLocation()))),
239+
ContentType.fromString(contentType.toString()), form, length, isFieldElementsIncluded, context)
240+
.map(response ->
241+
new FormRecognizerOperationResult(
242+
parseModelId(response.getDeserializedHeaders().getOperationLocation()))),
241243
form, recognizeCustomFormsOptions.getContentType()),
242244
pollingOperation(
243245
resultUuid -> service.getAnalyzeFormResultWithResponseAsync(
@@ -779,13 +781,13 @@ PollerFlux<FormRecognizerOperationResult, List<RecognizedForm>> beginRecognizeBu
779781
*/
780782
private Function<PollingContext<FormRecognizerOperationResult>, Mono<FormRecognizerOperationResult>>
781783
streamActivationOperation(
782-
Function<ContentType, Mono<FormRecognizerOperationResult>> activationOperation, Flux<ByteBuffer> form,
784+
Function<ContentType1, Mono<FormRecognizerOperationResult>> activationOperation, Flux<ByteBuffer> form,
783785
FormContentType contentType) {
784786
return pollingContext -> {
785787
try {
786788
Objects.requireNonNull(form, "'form' is required and cannot be null.");
787789
if (contentType != null) {
788-
return activationOperation.apply(ContentType.fromString(contentType.toString()))
790+
return activationOperation.apply(ContentType1.fromString(contentType.toString()))
789791
.onErrorMap(Utility::mapToHttpResponseExceptionIfExist);
790792
} else {
791793
return detectContentType(form)

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/FormRecognizerClientImpl.java

Lines changed: 403 additions & 219 deletions
Large diffs are not rendered by default.

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/FormRecognizerClientImplBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public final class FormRecognizerClientImplBuilder {
3232

3333
private final Map<String, String> properties = new HashMap<>();
3434

35+
/** Create an instance of the FormRecognizerClientImplBuilder. */
3536
public FormRecognizerClientImplBuilder() {
3637
this.pipelinePolicies = new ArrayList<>();
3738
}
@@ -155,7 +156,7 @@ public FormRecognizerClientImplBuilder retryPolicy(RetryPolicy retryPolicy) {
155156
/*
156157
* The list of Http pipeline policies to add.
157158
*/
158-
private List<HttpPipelinePolicy> pipelinePolicies;
159+
private final List<HttpPipelinePolicy> pipelinePolicies;
159160

160161
/**
161162
* Adds a custom Http pipeline policy.

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/Utility.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
package com.azure.ai.formrecognizer.implementation;
55

6-
import com.azure.ai.formrecognizer.implementation.models.ContentType;
6+
import com.azure.ai.formrecognizer.implementation.models.ContentType1;
77
import com.azure.ai.formrecognizer.implementation.models.ErrorResponseException;
88
import com.azure.ai.formrecognizer.models.FormRecognizerErrorInformation;
99
import com.azure.ai.formrecognizer.models.FormRecognizerOperationResult;
@@ -44,12 +44,12 @@ private Utility() {
4444
*
4545
* @param buffer The byte buffer input.
4646
*
47-
* @return The {@link Mono} of {@link ContentType} content type.
47+
* @return The {@link Mono} of {@link ContentType1} content type.
4848
*/
49-
public static Mono<ContentType> detectContentType(Flux<ByteBuffer> buffer) {
49+
public static Mono<ContentType1> detectContentType(Flux<ByteBuffer> buffer) {
5050
byte[] header = new byte[4];
5151
int[] written = new int[]{0};
52-
ContentType[] contentType = {ContentType.fromString("none")};
52+
ContentType1[] contentType = {ContentType1.fromString("none")};
5353
return buffer.map(chunk -> {
5454
final int len = chunk.remaining();
5555
for (int i = 0; i < len; i++) {
@@ -58,15 +58,15 @@ public static Mono<ContentType> detectContentType(Flux<ByteBuffer> buffer) {
5858

5959
if (written[0] == 4) {
6060
if (isJpeg(header)) {
61-
contentType[0] = ContentType.IMAGE_JPEG;
61+
contentType[0] = ContentType1.IMAGE_JPEG;
6262
} else if (isPdf(header)) {
63-
contentType[0] = ContentType.APPLICATION_PDF;
63+
contentType[0] = ContentType1.APPLICATION_PDF;
6464
} else if (isPng(header)) {
65-
contentType[0] = ContentType.IMAGE_PNG;
65+
contentType[0] = ContentType1.IMAGE_PNG;
6666
} else if (isTiff(header)) {
67-
contentType[0] = ContentType.IMAGE_TIFF;
67+
contentType[0] = ContentType1.IMAGE_TIFF;
6868
} else if (isBmp(header)) {
69-
contentType[0] = ContentType.IMAGE_BMP;
69+
contentType[0] = ContentType1.IMAGE_BMP;
7070
}
7171
// Got a four bytes matching or not, either way no need to read more byte return false
7272
// so that takeWhile can cut the subscription on data

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/models/ContentType.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ public enum ContentType {
1212
/** Enum value application/pdf. */
1313
APPLICATION_PDF("application/pdf"),
1414

15-
/** Enum value image/bmp. */
16-
IMAGE_BMP("image/bmp"),
17-
1815
/** Enum value image/jpeg. */
1916
IMAGE_JPEG("image/jpeg"),
2017

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
// Code generated by Microsoft (R) AutoRest Code Generator.
4+
5+
package com.azure.ai.formrecognizer.implementation.models;
6+
7+
import com.fasterxml.jackson.annotation.JsonCreator;
8+
import com.fasterxml.jackson.annotation.JsonValue;
9+
10+
/** Defines values for ContentType1. */
11+
public enum ContentType1 {
12+
/** Enum value application/pdf. */
13+
APPLICATION_PDF("application/pdf"),
14+
15+
/** Enum value image/bmp. */
16+
IMAGE_BMP("image/bmp"),
17+
18+
/** Enum value image/jpeg. */
19+
IMAGE_JPEG("image/jpeg"),
20+
21+
/** Enum value image/png. */
22+
IMAGE_PNG("image/png"),
23+
24+
/** Enum value image/tiff. */
25+
IMAGE_TIFF("image/tiff");
26+
27+
/** The actual serialized value for a ContentType1 instance. */
28+
private final String value;
29+
30+
ContentType1(String value) {
31+
this.value = value;
32+
}
33+
34+
/**
35+
* Parses a serialized value to a ContentType1 instance.
36+
*
37+
* @param value the serialized value to parse.
38+
* @return the parsed ContentType1 object, or null if unable to parse.
39+
*/
40+
@JsonCreator
41+
public static ContentType1 fromString(String value) {
42+
ContentType1[] items = ContentType1.values();
43+
for (ContentType1 item : items) {
44+
if (item.toString().equalsIgnoreCase(value)) {
45+
return item;
46+
}
47+
}
48+
return null;
49+
}
50+
51+
@JsonValue
52+
@Override
53+
public String toString() {
54+
return this.value;
55+
}
56+
}

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/models/Language.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public final class Language extends ExpandableStringEnum<Language> {
3131
/** Static value pt for Language. */
3232
public static final Language PT = fromString("pt");
3333

34+
/** Static value ja for Language. */
35+
public static final Language JA = fromString("ja");
36+
3437
/** Static value zh-Hans for Language. */
3538
public static final Language ZH_HANS = fromString("zh-Hans");
3639

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/models/Locale.java

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,40 @@
44

55
package com.azure.ai.formrecognizer.implementation.models;
66

7+
import com.azure.core.util.ExpandableStringEnum;
78
import com.fasterxml.jackson.annotation.JsonCreator;
8-
import com.fasterxml.jackson.annotation.JsonValue;
9+
import java.util.Collection;
910

1011
/** Defines values for Locale. */
11-
public enum Locale {
12-
/** Enum value en-AU. */
13-
EN_AU("en-AU"),
12+
public final class Locale extends ExpandableStringEnum<Locale> {
13+
/** Static value en-AU for Locale. */
14+
public static final Locale EN_AU = fromString("en-AU");
1415

15-
/** Enum value en-CA. */
16-
EN_CA("en-CA"),
16+
/** Static value en-CA for Locale. */
17+
public static final Locale EN_CA = fromString("en-CA");
1718

18-
/** Enum value en-GB. */
19-
EN_GB("en-GB"),
19+
/** Static value en-GB for Locale. */
20+
public static final Locale EN_GB = fromString("en-GB");
2021

21-
/** Enum value en-IN. */
22-
EN_IN("en-IN"),
22+
/** Static value en-IN for Locale. */
23+
public static final Locale EN_IN = fromString("en-IN");
2324

24-
/** Enum value en-US. */
25-
EN_US("en-US");
26-
27-
/** The actual serialized value for a Locale instance. */
28-
private final String value;
29-
30-
Locale(String value) {
31-
this.value = value;
32-
}
25+
/** Static value en-US for Locale. */
26+
public static final Locale EN_US = fromString("en-US");
3327

3428
/**
35-
* Parses a serialized value to a Locale instance.
29+
* Creates or finds a Locale from its string representation.
3630
*
37-
* @param value the serialized value to parse.
38-
* @return the parsed Locale object, or null if unable to parse.
31+
* @param name a name to look for.
32+
* @return the corresponding Locale.
3933
*/
4034
@JsonCreator
41-
public static Locale fromString(String value) {
42-
Locale[] items = Locale.values();
43-
for (Locale item : items) {
44-
if (item.toString().equalsIgnoreCase(value)) {
45-
return item;
46-
}
47-
}
48-
return null;
35+
public static Locale fromString(String name) {
36+
return fromString(name, Locale.class);
4937
}
5038

51-
@JsonValue
52-
@Override
53-
public String toString() {
54-
return this.value;
39+
/** @return known Locale values. */
40+
public static Collection<Locale> values() {
41+
return values(Locale.class);
5542
}
5643
}

sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/ContentTypeDetectionTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package com.azure.ai.formrecognizer;
55

66
import com.azure.ai.formrecognizer.implementation.Utility;
7-
import com.azure.ai.formrecognizer.implementation.models.ContentType;
7+
import com.azure.ai.formrecognizer.implementation.models.ContentType1;
88
import org.junit.jupiter.api.Test;
99
import reactor.core.publisher.Flux;
1010

@@ -33,7 +33,7 @@ public class ContentTypeDetectionTest {
3333
public void jpgContentDetectionTest() throws IOException {
3434
File sourceFile = new File("src/test/resources/sample_files/Test/contoso-allinone.jpg");
3535
Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(sourceFile.toPath())));
36-
assertEquals(ContentType.IMAGE_JPEG, detectContentType(buffer).block());
36+
assertEquals(ContentType1.IMAGE_JPEG, detectContentType(buffer).block());
3737
}
3838

3939
/**
@@ -45,7 +45,7 @@ public void jpgContentDetectionTest() throws IOException {
4545
public void pdfContentDetectionTest() throws IOException {
4646
File sourceFile = new File("src/test/resources/sample_files/Test/Invoice_6.pdf");
4747
Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(sourceFile.toPath())));
48-
assertEquals(ContentType.APPLICATION_PDF, detectContentType(buffer).block());
48+
assertEquals(ContentType1.APPLICATION_PDF, detectContentType(buffer).block());
4949
}
5050

5151
/**
@@ -57,7 +57,7 @@ public void pdfContentDetectionTest() throws IOException {
5757
public void pngContentDetectionTest() throws IOException {
5858
File sourceFile = new File("src/test/resources/sample_files/Test/pngFile.png");
5959
Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(sourceFile.toPath())));
60-
assertEquals(ContentType.IMAGE_PNG, detectContentType(buffer).block());
60+
assertEquals(ContentType1.IMAGE_PNG, detectContentType(buffer).block());
6161
}
6262

6363
/**
@@ -69,7 +69,7 @@ public void pngContentDetectionTest() throws IOException {
6969
public void tiffLittleEndianContentDetectionTest() throws IOException {
7070
File sourceFile = new File("src/test/resources/sample_files/Test/cell.tif");
7171
Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(sourceFile.toPath())));
72-
assertEquals(ContentType.IMAGE_TIFF, detectContentType(buffer).block());
72+
assertEquals(ContentType1.IMAGE_TIFF, detectContentType(buffer).block());
7373
}
7474

7575
/**
@@ -79,7 +79,7 @@ public void tiffLittleEndianContentDetectionTest() throws IOException {
7979
@Test
8080
public void tiffBigEndianContentDetectionTest() {
8181
Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(new byte[]{0x4D, 0x4D, 0x00, 0x2A}));
82-
assertEquals(ContentType.IMAGE_TIFF, detectContentType(buffer).block());
82+
assertEquals(ContentType1.IMAGE_TIFF, detectContentType(buffer).block());
8383
}
8484

8585
/**
@@ -103,6 +103,6 @@ public void notSupportContentDetectionTest() throws IOException {
103103
public void bmpContentDetectionTest() throws IOException {
104104
File sourceFile = new File("src/test/resources/sample_files/Test/sample_bmp.bmp");
105105
Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(sourceFile.toPath())));
106-
assertEquals(ContentType.IMAGE_BMP, detectContentType(buffer).block());
106+
assertEquals(ContentType1.IMAGE_BMP, detectContentType(buffer).block());
107107
}
108108
}

sdk/formrecognizer/azure-ai-formrecognizer/swagger/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ autorest --java --use=C:/work/autorest.java
2020

2121
### Code generation settings
2222
``` yaml
23-
input-file: ./fr_2.1-preview.2.json
23+
input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/cognitiveservices/data-plane/FormRecognizer/preview/v2.1-preview.2/FormRecognizer.json
2424
java: true
2525
output-folder: ..\
2626
generate-client-as-impl: true

0 commit comments

Comments
 (0)