{"id":486239,"date":"2026-07-05T13:10:32","date_gmt":"2026-07-05T13:10:32","guid":{"rendered":"https:\/\/savepearlharbor.com\/?p=486239"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=486239","title":{"rendered":"\u041a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0438\u0437 \u043a\u043e\u0434\u0430, \u043a\u043b\u0438\u0435\u043d\u0442 \u0438\u0437 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430: \u0438\u0437\u0431\u0430\u0432\u043b\u044f\u0435\u043c\u0441\u044f \u043e\u0442 \u0442\u0440\u043e\u0439\u043d\u043e\u0433\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 API"},"content":{"rendered":"<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 API \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a: \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. \u0417\u0430\u0442\u0435\u043c \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0435\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0444\u0440\u043e\u043d\u0442\u0435\u0440, \u043e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u0442\u0430\u043a\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u043f\u0438\u0448\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442.<\/p>\n<p>\u041c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u0442\u0440\u0438\u0436\u0434\u044b.<\/p>\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/articles\/1047686\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b, \u043a\u0430\u043a \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0430\u043d\u0434\u043b\u0430 <a href=\"https:\/\/github.com\/sunrise-studio-development\/symfony-openapi\" rel=\"noopener noreferrer nofollow\">sunrise-studio\/symfony-openapi<\/a> \u043c\u043e\u0436\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0438\u0437 \u043a\u043e\u0434\u0430, \u043c\u0438\u043d\u0443\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>\u041d\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443. \u0415\u0441\u043b\u0438 OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0438\u0437 \u043a\u043e\u0434\u0430, \u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0442\u0435\u043a\u0430\u0442\u044c \u0438\u0437 OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430. \u0418\u043d\u0430\u0447\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u2013 \u0438 \u0435\u0441\u0442\u044c \u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0437\u0430\u043c\u043a\u043d\u0443\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443:<br \/><strong>Controller \u2192 OpenAPI \u2192 Client \u2192 Feature<\/strong><br \/>\u0413\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e, \u0430 \u043d\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e.\u00a0<\/p>\n<hr\/>\n<h3>\u041e\u0433\u043b\u044f\u043d\u0435\u043c\u0441\u044f \u043d\u0430\u0437\u0430\u0434<\/h3>\n<p><span class=\"habrahidden\">\ud83c\udfb6 Carry On Wayward Son \ud83c\udfb6<\/span><\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<pre><code class=\"php\">#[Route('\/v1\/completions', name: 'createCompletion', methods: ['POST'])]final readonly class CreateCompletionController{    public function __invoke(        #[MapRequestPayload] CreateCompletionRequest $request,    ): CompletionView {        \/\/ ...    }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:87px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0418\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0430\u043d\u0434\u043b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u0430 \u043d\u0435 \u043a\u0430\u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"json\">{  \"openapi\": \"3.1.1\",  \"info\": {    \"title\": \"app\",    \"version\": \"1.0.0\"  },  \"paths\": {    \"\/v1\/completions\": {      \"post\": {        \"responses\": {          \"default\": {            \"description\": \"The operation was unsuccessful.\",            \"content\": {              \"application\/json\": {                \"schema\": {                  \"$ref\": \"#\/components\/schemas\/ErrorResponseView\"                }              }            }          },          \"201\": {            \"description\": \"The operation was successful.\",            \"content\": {              \"application\/json\": {                \"schema\": {                  \"$ref\": \"#\/components\/schemas\/CompletionView\"                }              }            }          }        },        \"requestBody\": {          \"content\": {            \"application\/json\": {              \"schema\": {                \"$ref\": \"#\/components\/schemas\/CreateCompletionRequest\"              }            }          },          \"required\": true        },        \"operationId\": \"createCompletion\",        \"tags\": [          \"Completions\"        ],        \"summary\": \"Creates completion\",        \"description\": \"Creates text completion for the given prompt.\"      }    }  },  \"components\": {    \"schemas\": {      \"ErrorView\": {        \"type\": \"object\",        \"additionalProperties\": false,        \"properties\": {          \"key\": {            \"type\": \"string\"          },          \"message\": {            \"type\": \"string\"          }        },        \"required\": [          \"key\",          \"message\"        ]      },      \"ErrorResponseView\": {        \"type\": \"object\",        \"additionalProperties\": false,        \"properties\": {          \"message\": {            \"type\": \"string\"          },          \"errors\": {            \"type\": \"array\",            \"items\": {              \"$ref\": \"#\/components\/schemas\/ErrorView\"            }          }        },        \"required\": [          \"message\"        ]      },      \"CompletionView\": {        \"type\": \"object\",        \"additionalProperties\": false,        \"properties\": {          \"text\": {            \"type\": \"string\"          }        },        \"required\": [          \"text\"        ]      },      \"CreateCompletionRequest\": {        \"type\": \"object\",        \"additionalProperties\": false,        \"properties\": {          \"prompt\": {            \"type\": \"string\"          }        },        \"required\": [          \"prompt\"        ]      }    }  }}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<h3>\u041a\u043b\u0438\u0435\u043d\u0442 \u0438\u0437 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430<\/h3>\n<p>\u041a\u0430\u043a \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0431\u044b\u043b \u0432\u044b\u0432\u0435\u0434\u0435\u043d \u0438\u0437 \u043a\u043e\u0434\u0430, \u0442\u0430\u043a \u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0432\u0435\u0434\u0435\u043d \u0438\u0437 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <a href=\"https:\/\/orval.dev\/\" rel=\"noopener noreferrer nofollow\">Orval<\/a> \u2013 \u043f\u0430\u043a\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0438\u0437 OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430.<\/p>\n<pre><code class=\"bash\">orval --input http:\/\/localhost:8000\/docs\/openapi.json --output .\/src\/api\/client.ts<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<details class=\"spoiler\">\n<summary>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"typescript\">\/** * Generated by orval v7.10.0 \ud83c\udf7a * Do not edit manually. * app * OpenAPI spec version: 1.0.0 *\/import axios from 'axios';import type {  AxiosRequestConfig,  AxiosResponse} from 'axios';export interface ErrorView {  key: string;  message: string;}export interface ErrorResponseView {  message: string;  errors?: ErrorView[];}export interface CompletionView {  text: string;}export interface CreateCompletionRequest {  prompt: string;}\/** * Creates text completion for the given prompt. * @summary Creates completion *\/export const createCompletion = &lt;TData = AxiosResponse&lt;CompletionView&gt;&gt;(    createCompletionRequest: CreateCompletionRequest, options?: AxiosRequestConfig ): Promise&lt;TData&gt; =&gt; {    return axios.post(      `\/v1\/completions`,      createCompletionRequest,options    );  }export type CreateCompletionResult = AxiosResponse&lt;CompletionView&gt;<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<\/div>\n<\/details>\n<p>\u0420\u044f\u0434\u043e\u043c \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c bootstrap.ts, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0435\u0433\u043e.<\/p>\n<pre><code class=\"typescript\">import axios from 'axios';axios.defaults.baseURL = 'http:\/\/localhost:8000';<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0432 \u0442\u043e\u0447\u043a\u0435, \u043a\u043e\u0433\u0434\u0430 \u0440\u0443\u043a\u0430\u043c\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2013 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u043e\u0439\u043b\u0435\u0440\u043f\u043b\u0435\u0439\u0442\u0430 \u043c\u044b \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u0444\u0438\u0447\u0435.<\/p>\n<pre><code class=\"typescript\">import React from 'react';import { Button, Text, TextInput, View } from 'react-native';import { Controller, useForm } from 'react-hook-form';import { createCompletion, CreateCompletionRequest } from '@\/src\/api\/client';export default function CompletionForm() {  const {    control,    handleSubmit,    setError,    formState: {      isSubmitting,    },  } = useForm&lt;CreateCompletionRequest&gt;({    defaultValues: {      prompt: '',    },  });  const onSubmit = (data: CreateCompletionRequest) =&gt; createCompletion(data, {    setFormError: setError,  }).then(response =&gt; {    \/\/ some logic  }).catch(error =&gt; {    \/\/ error handling  });  return (    &lt;View&gt;      &lt;Controller        name=\"prompt\"        control={control}        render={({ field: { value, onChange }, fieldState: { error } }) =&gt; (          &lt;View&gt;            &lt;TextInput value={value} onChangeText={onChange} placeholder=\"Prompt\" \/&gt;            {error &amp;&amp; &lt;Text&gt;{error.message}&lt;\/Text&gt;}          &lt;\/View&gt;        )}      \/&gt;      &lt;Button title=\"Complete\" disabled={isSubmitting} onPress={handleSubmit(onSubmit)} \/&gt;    &lt;\/View&gt;  );}<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<p><em>\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0448\u0435 \u043d\u0430 \u0431\u0430\u0437\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0441\u0442\u0435\u043a\u0430 (React Native \u0438 react-hook-form), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u043c \u0438 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 Orval.<\/em><\/p>\n<h3>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/h3>\n<p>\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u044b\u043b\u0430 \u0432\u044b\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0447\u0438\u0441\u0442\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0430 \u0431\u044d\u043a\u0435, \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0435\u0449\u0435 \u0442\u043e\u043d\u044c\u0448\u0435. \u0424\u043e\u0440\u043c\u0430 \u0432\u044b\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0430\u0445, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c bootstrap.ts.<\/p>\n<pre><code class=\"typescript\">import axios from 'axios';import { ErrorResponseView, ErrorView } from '.\/client';import { UseFormSetError } from 'react-hook-form';declare module 'axios' {  interface AxiosRequestConfig {    setFormError?: UseFormSetError&lt;any&gt;;  }}axios.defaults.baseURL = 'http:\/\/localhost:8000';axios.interceptors.response.use(  response =&gt; response,  error =&gt; {    if (axios.isAxiosError&lt;ErrorResponseView&gt;(error)) {      error.response?.data?.errors?.forEach((errorView: ErrorView) =&gt; {        error.config?.setFormError?.(errorView.key, {          message: errorView.message,        });      });    }    return Promise.reject(error);  },);<\/code><div class=\"code-explainer\"><a href=\"https:\/\/sourcecraft.dev\/\" class=\"tm-button code-explainer__link\" style=\"visibility: hidden;\"><img style=\"width:14px;height:14px;object-fit:cover;object-position:left;\"\/><\/a><\/div><\/pre>\n<hr\/>\n<p>\u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043d\u0430 \u0441\u043f\u0438\u0447\u043a\u0430\u0445, \u043d\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043c\u0435\u043b\u043e\u0447\u0435\u0439 \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u0447\u0438\u0441\u0442\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430.<\/p>\n<\/div>\n<p>\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/1055764\/\">https:\/\/habr.com\/ru\/articles\/1055764\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 API \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a: \u043c\u044b \u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440. \u0417\u0430\u0442\u0435\u043c \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0435\u0433\u043e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0444\u0440\u043e\u043d\u0442\u0435\u0440, \u043e\u043f\u0438\u0440\u0430\u044f\u0441\u044c \u043d\u0430 \u0442\u0430\u043a\u0443\u044e \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e, \u043f\u0438\u0448\u0435\u0442 \u043a\u043b\u0438\u0435\u043d\u0442.\u041c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u0442\u0440\u0438\u0436\u0434\u044b.\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u043b, \u043a\u0430\u043a \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0431\u0430\u043d\u0434\u043b\u0430 sunrise-studio\/symfony-openapi \u043c\u043e\u0436\u043d\u043e \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0438\u0437 \u043a\u043e\u0434\u0430, \u043c\u0438\u043d\u0443\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f.\u041d\u043e \u044d\u0442\u043e \u0440\u0435\u0448\u0430\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443. \u0415\u0441\u043b\u0438 OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0438\u0437 \u043a\u043e\u0434\u0430, \u0442\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0442\u0435\u043a\u0430\u0442\u044c \u0438\u0437 OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430. \u0418\u043d\u0430\u0447\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u2013 \u0438 \u0435\u0441\u0442\u044c \u0442\u043e \u0441\u0430\u043c\u043e\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043a\u0430\u043a \u0437\u0430\u043c\u043a\u043d\u0443\u0442\u044c \u0446\u0435\u043f\u043e\u0447\u043a\u0443:Controller \u2192 OpenAPI \u2192 Client \u2192 Feature\u0413\u0434\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0438\u0437 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e, \u0430 \u043d\u0435 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u0435\u0442 \u0435\u0433\u043e.\u00a0\u041e\u0433\u043b\u044f\u043d\u0435\u043c\u0441\u044f \u043d\u0430\u0437\u0430\u0434\ud83c\udfb6 Carry On Wayward Son \ud83c\udfb6\u041d\u0430\u043f\u043e\u043c\u043d\u044e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438:#[Route(&#8216;\/v1\/completions&#8217;, name: &#8216;createCompletion&#8217;, methods: [&#8216;POST&#8217;])]final readonly class CreateCompletionController{    public function __invoke(        #[MapRequestPayload] CreateCompletionRequest $request,    ): CompletionView {        \/\/ &#8230;    }}\u0418\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0430\u043d\u0434\u043b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442, \u0430 \u043d\u0435 \u043a\u0430\u043a \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f.\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442{  &#171;openapi&#187;: &#171;3.1.1&#187;,  &#171;info&#187;: {    &#171;title&#187;: &#171;app&#187;,    &#171;version&#187;: &#171;1.0.0&#187;  },  &#171;paths&#187;: {    &#171;\/v1\/completions&#187;: {      &#171;post&#187;: {        &#171;responses&#187;: {          &#171;default&#187;: {            &#171;description&#187;: &#171;The operation was unsuccessful.&#187;,            &#171;content&#187;: {              &#171;application\/json&#187;: {                &#171;schema&#187;: {                  &#171;$ref&#187;: &#171;#\/components\/schemas\/ErrorResponseView&#187;                }              }            }          },          &#171;201&#187;: {            &#171;description&#187;: &#171;The operation was successful.&#187;,            &#171;content&#187;: {              &#171;application\/json&#187;: {                &#171;schema&#187;: {                  &#171;$ref&#187;: &#171;#\/components\/schemas\/CompletionView&#187;                }              }            }          }        },        &#171;requestBody&#187;: {          &#171;content&#187;: {            &#171;application\/json&#187;: {              &#171;schema&#187;: {                &#171;$ref&#187;: &#171;#\/components\/schemas\/CreateCompletionRequest&#187;              }            }          },          &#171;required&#187;: true        },        &#171;operationId&#187;: &#171;createCompletion&#187;,        &#171;tags&#187;: [          &#171;Completions&#187;        ],        &#171;summary&#187;: &#171;Creates completion&#187;,        &#171;description&#187;: &#171;Creates text completion for the given prompt.&#187;      }    }  },  &#171;components&#187;: {    &#171;schemas&#187;: {      &#171;ErrorView&#187;: {        &#171;type&#187;: &#171;object&#187;,        &#171;additionalProperties&#187;: false,        &#171;properties&#187;: {          &#171;key&#187;: {            &#171;type&#187;: &#171;string&#187;          },          &#171;message&#187;: {            &#171;type&#187;: &#171;string&#187;          }        },        &#171;required&#187;: [          &#171;key&#187;,          &#171;message&#187;        ]      },      &#171;ErrorResponseView&#187;: {        &#171;type&#187;: &#171;object&#187;,        &#171;additionalProperties&#187;: false,        &#171;properties&#187;: {          &#171;message&#187;: {            &#171;type&#187;: &#171;string&#187;          },          &#171;errors&#187;: {            &#171;type&#187;: &#171;array&#187;,            &#171;items&#187;: {              &#171;$ref&#187;: &#171;#\/components\/schemas\/ErrorView&#187;            }          }        },        &#171;required&#187;: [          &#171;message&#187;        ]      },      &#171;CompletionView&#187;: {        &#171;type&#187;: &#171;object&#187;,        &#171;additionalProperties&#187;: false,        &#171;properties&#187;: {          &#171;text&#187;: {            &#171;type&#187;: &#171;string&#187;          }        },        &#171;required&#187;: [          &#171;text&#187;        ]      },      &#171;CreateCompletionRequest&#187;: {        &#171;type&#187;: &#171;object&#187;,        &#171;additionalProperties&#187;: false,        &#171;properties&#187;: {          &#171;prompt&#187;: {            &#171;type&#187;: &#171;string&#187;          }        },        &#171;required&#187;: [          &#171;prompt&#187;        ]      }    }  }}\u041a\u043b\u0438\u0435\u043d\u0442 \u0438\u0437 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430\u041a\u0430\u043a \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442 \u0431\u044b\u043b \u0432\u044b\u0432\u0435\u0434\u0435\u043d \u0438\u0437 \u043a\u043e\u0434\u0430, \u0442\u0430\u043a \u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432\u044b\u0432\u0435\u0434\u0435\u043d \u0438\u0437 \u043a\u043e\u043d\u0442\u0440\u0430\u043a\u0442\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c Orval \u2013 \u043f\u0430\u043a\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0438\u0437 OpenAPI-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430.orval &#8212;input http:\/\/localhost:8000\/docs\/openapi.json &#8212;output .\/src\/api\/client.ts\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442\/** * Generated by orval v7.10.0 \ud83c\udf7a * Do not edit manually. * app * OpenAPI spec version: 1.0.0 *\/import axios from &#8216;axios&#8217;;import type {  AxiosRequestConfig,  AxiosResponse} from &#8216;axios&#8217;;export interface ErrorView {  key: string;  message: string;}export interface ErrorResponseView {  message: string;  errors?: ErrorView[];}export interface CompletionView {  text: string;}export interface CreateCompletionRequest {  prompt: string;}\/** * Creates text completion for the given prompt. * @summary Creates completion *\/export const createCompletion = &lt;TData = AxiosResponse&lt;CompletionView&gt;&gt;(    createCompletionRequest: CreateCompletionRequest, options?: AxiosRequestConfig ): Promise&lt;TData&gt; =&gt; {    return axios.post(      `\/v1\/completions`,      createCompletionRequest,options    );  }export type CreateCompletionResult = AxiosResponse&lt;CompletionView&gt;\u0420\u044f\u0434\u043e\u043c \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c bootstrap.ts, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0435\u0433\u043e.import axios from &#8216;axios&#8217;;axios.defaults.baseURL = &#8216;http:\/\/localhost:8000&#8217;;\u0412 \u0438\u0442\u043e\u0433\u0435 \u043c\u044b \u043d\u0430\u0445\u043e\u0434\u0438\u043c\u0441\u044f \u0432 \u0442\u043e\u0447\u043a\u0435, \u043a\u043e\u0433\u0434\u0430 \u0440\u0443\u043a\u0430\u043c\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2013 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043e. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0431\u043e\u0439\u043b\u0435\u0440\u043f\u043b\u0435\u0439\u0442\u0430 \u043c\u044b \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u0443\u0435\u043c\u0441\u044f \u043d\u0430 \u0444\u0438\u0447\u0435.import React from &#8216;react&#8217;;import { Button, Text, TextInput, View } from &#8216;react-native&#8217;;import { Controller, useForm } from &#8216;react-hook-form&#8217;;import { createCompletion, CreateCompletionRequest } from &#8216;@\/src\/api\/client&#8217;;export default function CompletionForm() {  const {    control,    handleSubmit,    setError,    formState: {      isSubmitting,    },  } = useForm&lt;CreateCompletionRequest&gt;({    defaultValues: {      prompt: &#187;,    },  });  const onSubmit = (data: CreateCompletionRequest) =&gt; createCompletion(data, {    setFormError: setError,  }).then(response =&gt; {    \/\/ some logic  }).catch(error =&gt; {    \/\/ error handling  });  return (    &lt;View&gt;      &lt;Controller        name=&#187;prompt&#187;        control={control}        render={({ field: { value, onChange }, fieldState: { error } }) =&gt; (          &lt;View&gt;            &lt;TextInput value={value} onChangeText={onChange} placeholder=&#187;Prompt&#187; \/&gt;            {error &amp;&amp; &lt;Text&gt;{error.message}&lt;\/Text&gt;}          &lt;\/View&gt;        )}      \/&gt;      &lt;Button title=&#187;Complete&#187; disabled={isSubmitting} onPress={handleSubmit(onSubmit)} \/&gt;    &lt;\/View&gt;  );}\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0448\u0435 \u043d\u0430 \u0431\u0430\u0437\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u043e\u0433\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0441\u0442\u0435\u043a\u0430 (React Native \u0438 react-hook-form), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u043c \u0438 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 Orval.\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u044b\u043b\u0430 \u0432\u044b\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0447\u0438\u0441\u0442\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0430 \u0431\u044d\u043a\u0435, \u043d\u0430 \u0444\u0440\u043e\u043d\u0442\u0435 \u043e\u043d\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0435\u0449\u0435 \u0442\u043e\u043d\u044c\u0448\u0435. \u0424\u043e\u0440\u043c\u0430 \u0432\u044b\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u043e\u0440\u0430\u0431\u043e\u0442\u043a\u0430\u0445, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c bootstrap.ts.import axios from &#8216;axios&#8217;;import { ErrorResponseView, ErrorView } from &#8216;.\/client&#8217;;import { UseFormSetError } from &#8216;react-hook-form&#8217;;declare module &#8216;axios&#8217; {  interface AxiosRequestConfig {    setFormError?: UseFormSetError&lt;any&gt;;  }}axios.defaults.baseURL = &#8216;http:\/\/localhost:8000&#8217;;axios.interceptors.response.use(  response =&gt; response,  error =&gt; {    if (axios.isAxiosError&lt;ErrorResponseView&gt;(error)) {      error.response?.data?.errors?.forEach((errorView: ErrorView) =&gt; {        error.config?.setFormError?.(errorView.key, {          message: errorView.message,        });      });    }    return Promise.reject(error);  },);\u041c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043d\u0430 \u0441\u043f\u0438\u0447\u043a\u0430\u0445, \u043d\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0438\u0437 \u0442\u0430\u043a\u0438\u0445 \u043c\u0435\u043b\u043e\u0447\u0435\u0439 \u0441\u0442\u0440\u043e\u0438\u0442\u0441\u044f \u0447\u0438\u0441\u0442\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430.\u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 https:\/\/habr.com\/ru\/articles\/1055764\/<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-486239","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/486239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=486239"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/486239\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=486239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=486239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=486239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}