+ if (channel == null) {
+ generator.writeObjectFieldStart("components");
+ generator.flush();
+ channel = Channels.newChannel(new ByteArrayInputStream(stream.toByteArray()));
+ stream.reset();
+ }
+
+ var read = channel.read(ByteBuffer.wrap(array, off, len));
+ while (read == -1) {
+ if (!schemasWritten) {
+ channel = Channels.newChannel(new SchemasStream(context, writer, generator, stream, iterator,
+ isForSingleModule));
+ read = channel.read(ByteBuffer.wrap(array));
+ schemasWritten = true;
+ continue;
+ }
+ if (!securityWritten) {
+ channel = Channels.newChannel(new SecuritySchemesStream(writer, Map.of(BASIC_AUTH_NAME,
+ OPEN_API_BASIC_AUTH)));
+ read = channel.read(ByteBuffer.wrap(array, off, len));
+ securityWritten = true;
+ generator.writeEndObject();
+ continue;
+ }
+ generator.flush();
+ channel = Channels.newChannel(new ByteArrayInputStream(stream.toByteArray()));
+ stream.reset();
+ return channel.read(ByteBuffer.wrap(array, off, len));
+ }
+ return read;