Penpot API file for autogenerating API libraries? 🤔 e.g. OpenAPI

Hi there fellow Penpot aficionados,

I’ve been digging in the API documentation for some time, while making my first Python API library that will communicate with Penpot’s backend. I’ve noticed when making the library, there is a ginormous list of functions that I need to write, which most of the time do the same thing. Thinking about it, even if I had created all the functions to communicate with all the APIs, if any of the API would change, I would need to update my library’s functions manually.

Currently I’m scrubbing information from the Builtin API documentation page to auto generate python API functions, but I don’t think it is sustainable, because if someone changes the format of the HTML page, my scrubbing script would go boom:boom:.

example of a WIP generated function

def create_comment(session: Session, profile_id :str, thread_id :str, content :str, share_id :str) -> str:
	"""
	tag: AUTH,
	Added: on v1.15,

	Parameters
	----------
	Required
	profile_id : str, required
	thread_id : str, required
	content : str, required

	Optional
	share_id : str, optional
	"""
	if profile_id is None: raise ValueError('profile-id is not set')
	if thread_id is None:  raise ValueError('thread-id is not set')
	if content is None:    raise ValueError('content is not set')

	headers = { "Content-Type": "application/json" }
	payload = { "profile-id": profile_id, "thread-id": thread_id, "content": content }

	if share_id is None: payload["share-id"] = share_id

	succeded, response = sendRequest(session, 'POST', apiEndpoint, headers, payload)

I’d suggest having a resource where developers can get the API information in a format that lends itself to easily generate API library boilerplate. It can something plane as a JSON file, but looking on the internet, there is an open-source standard called OpenAPI and a code generation tool called Swagger-Codegen. It is able to generate API client libraries, server stubs and documentation automatically based on an OpenAPI file to a large variety of programming languages and frameworks.

I’m still green in this area of web API development and Clojure, since I come from a game development background, so I’m open to any suggestions of alternatives from people with more knowledge in the field.

Also added a Github feature request #3034

3 Likes