Edits history of script submission #18535 for ' Create a recipe (readme)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Create a recipe
     * Create a new recipe in your ReadMe project.
    
    >📘
    > This route is only available to projects that are using [ReadMe Refactored](https://docs.readme.com/main/docs/welcome-to-readme-refactored).
     */
    export async function main(auth: RT.Readme, branch: string, body: Body) {
    	const url = new URL(`https://api.readme.com/v2/branches/${branch}/recipes`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    
    /* eslint-disable */
    /**
     * This file was automatically generated by json-schema-to-typescript.
     * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
     * and run json-schema-to-typescript to regenerate this file.
     */
    
    export interface Body {
    	appearance?: {
    		/**
    		 * The color of the recipe card.
    		 */
    		background_color?: string
    		emoji?: string
    	}
    	connections?: {
    		references?: {
    			/**
    			 * URI of the API reference page that this recipe will be connected to. The API reference and recipe must exist within the same version.
    			 */
    			uri?: string
    		}[]
    	}
    	content: {
    		steps?: {
    			/**
    			 * Title of the step.
    			 */
    			title?: string
    			body?: string
    			/**
    			 * Line numbers to highlight in the code snippet. (e.g. `["1-5", "10"]).
    			 */
    			line_numbers?: string[]
    		}[]
    		snippet?: {
    			/**
    			 * Array of code snippets to display in the recipe.
    			 */
    			code_options?: {
    				code?: string
    				/**
    				 * Language of the code snippet.
    				 */
    				language?: string
    				name?: string
    				highlighted_syntax?: string
    			}[]
    		}
    		response?: string
    	}
    	description: string
    	privacy?: {
    		/**
    		 * Who can view the recipe.
    		 */
    		view?: 'public' | 'anyone_with_link'
    	}
    	title: string
    }
    

    Submitted by hugo697 235 days ago